Quantcast
Channel: Active questions tagged string-manipulation - Mathematica Stack Exchange
Browsing latest articles
Browse All 201 View Live
↧

How to define a mixed pattern consisting of string and regular patterns for...

I'm kinda stuck here, and I could really use some help:I want to define a function, let's call it quarterValue, that accepts a Rule as an input and returns an appropriate expression as output.A...

View Article


Splitting a string into substrings of length 1 and 2

There is already a thread on how to split a string into equal sized chunks.I'm wanting to split a string into sets of substrings of length 1 and 2.For example, if I have the string "123456", my list...

View Article


Randomly reversing a substring

I was thinking about how to make this with the StringReverse, but I failed:I have a sequence of (for example):str = "FDSRTYNHFNKHLIUHG";I wish to reverse a randomly long contiguous sequence of...

View Article

read Python-generated data file

I've read similar-but-not-quite-the-same questions : I have to read a python-generated data file which contains complex numbers. So, the numbers appear as (real+imag j). And of course Mathematica read...

View Article

A function that maps Held symbol to string

Rougly my question is about constructing a function that maps Hold[var] to "var"even when var has an assigned value. In details :In[1] var=22; A=Hold[var];Can we construct a function F such thatF[A]...

View Article


Split a String by minus and zero

How can a String like0.0002230.0012730.000296-0.0014380.0011270.0014690.001457-0.001017`be converted to{0.000223, 0.001273, 0.000296, -0.001438, 0.001127, 0.001469, 0.001457, -0.001017}

View Article

Remove expression with matched braces from string

I am writing a LaTeX document where the custom command \chg{...} highlights changes in some color. Here I am, with a document of about 50 of those. Sure, one could just remove "\chg" everywhere, but...

View Article

How to extract citations from a document

I would like to extract citations from a document. I can use the following:txt = "Lorem ipsum dolor sit amet Name0 (2000), consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et...

View Article


NYT Spelling Bee puzzle

I've written some code that provides answers to the daily NYT Spelling Bee puzzles which ask you to find words that can be constructed from 7 given letters, one of which must be present in each...

View Article


How to separate a filename from its extension [closed]

Is there a function that separates a filename from the extension? E.g.MyNotebook.nbwould become{ "MyNotebook", ".nb" }I looked at FileNameSplit[], but that leaves "MyNotebook.nb" as the last...

View Article

Turn string with () as function brackets into expression

I have a text file with an equation where all the brackets are formatted as (). For example I read in the equation 2*(Re(a)+Im(b)) as a string. Now I am wondering if I can make this into an expression...

View Article

How to get the desired LLM response in string robustly with and without using...

I am trying to query a large language model from VS code using WolframEngine.However, ImportSting with JSON options does not work in extract the desired output string of the LLM response. So I use the...

View Article

Image may be NSFW.
Clik here to view.

How to properly write fraction in style

I would like to write the following for the legend of a curve :$$ Theta = \frac{\pi}{2}$$Where the value $\frac{\pi}{2}$ is actually in a variable named $Theta$ (same name as the text on the lhs of the...

View Article


Match two lists based on same elements

I have two large lists:list1 = {{a,v},{a,h},{b,v},{b,k},{c,t},{c,r},{d,r}};list2 = {{v,dc},{v,rt},{h,kl},{h,oi},{h,po},{k,ö},{k,dc},{t,re},{r,qw},{r,ay},{r,ül}};Now I want a list that matches both...

View Article

How to speed up ToString[#,TeXForm]&?

Try the following code to convert the expression to LaTeX codef = Expand[(x/2 + y/3 + z/5 + 1/7)^20];str = ToString[f,TeXForm]; // AbsoluteTimingIt took about 1 minute, while sympy.latex only took 0.6...

View Article


How to parse out a word's position in a data set

I'm trying to find better ways to import data. My data set is a CSV that contains a parameters at the end of the file. For example in this two part list I want to find the position at which the word...

View Article

Converting variable value to a string [duplicate]

I can run this with no problem:Import[NotebookDirectory[] <> "a10.mx"];Instead of that, I want to describe 10 with a variable as k,k = 10;Import[NotebookDirectory[] <> StringForm["a``.mx",...

View Article


How to set to 0 all terms in a matrix which contain a minus, revisited

The previous question How to set to 0 all terms in a matrix which contain a minus seems to have a wrong answer. For the matrixM = {{-ai - ar + ba s - \[Mu], bi s}, {ai, -\[Gamma]i - \[Delta] -...

View Article

Escaping multiline strings in Mathematica

I want to assign long multi-line strings in Mathematica. Is there a way of delineating a block without having to escape each instance of '"' with '\"' and each line ending with '\'?i.e. In other...

View Article

How to delete line breaks in imported data

I am having a lot of issues trying to import data into mathematica and then clean the data so that mathematica recognises it. The data is a set of permutations, which I would like to express as...

View Article

Image may be NSFW.
Clik here to view.

Duplicated points not labeled when presented to ListPlot as point->"label"

A minimal working example is given via:{{{1, 4} -> "A"}, {{2, 2} -> "B"}, {{3, 1} -> "C"}, {{3, 7} -> "D"}, {{4, 5} -> "E"}, {{4, 5} -> "F"}, {{5, 3} -> "G"}, {{6, 6}...

View Article


Image may be NSFW.
Clik here to view.

Displaying a string on fixed-width lines

Is it possible to format/style a string/text so that it is displayed in lines of fixed character length like on image without converting it to list of characters?str = Mod[Range[0, 105], 26] /....

View Article


What is the behavior of `FromRomanNumeral` on inputs with non-roman characters?

The documentation for the FromRomanNumeral function states thatany combination of valid digits is interpreted as an integer:digits = {"I", "V", "X", "L", "C", "D", "M"}…Nowhere does it explicitly state...

View Article

How to parse a parenthesized arithmetic string into a minimal-parentheses...

I have arithmetic expressions given as strings with excessive parentheses, and I want to convert them into symbolic Mathematica expressions that retain their structure but are formatted with only the...

View Article

Finding position of corresponding parentheses in expression

Suppose we have an expression in InputForm as a string. The task is to find position of corresponding parentheses. For example parenthesis at position 7 is closed by parenthesis at position 29 of...

View Article


Image may be NSFW.
Clik here to view.

Fibonacci word generator and Density of Fibonacci subwords

Reference: arXiv:2505.00602Reproduce Table I(* Fibonacci Words Generator - Corrected Port from Python *)(* Port of fibonacci_words_up_to(n) function *)fibonacciWordsUpTo[n_] := Module[{fibWords}, (*...

View Article

Shortest strings surrounded by other strings

This is probably trivial, but it has been quite a long time since I last used Shortest and now I can not figure out how to do the following properly.Shortest string that contains "A" surrounded by "0"...

View Article

String pattern search and replacement -- it works, but produces error...

I defined a function in Mathematica to process a pre-generated string. More specifically, I'd like to process some parts of C codes generated from MMA. Basically what my function does is to expand the...

View Article

How to get Mathematica to ignore spaces in a cipher

The code outputs False and True. For whatever reason, the space outputs as a "#" and I can't figure out how to make it ignore it and just go ahead with the test. I basically want the space to be...

View Article



Help with understanding how Blank, BlankSequence, and BlankNullSequence work...

I have a string myStr that contains a representation of today's date (Monday, February 23):myStr = "M 2/23";I'm trying to understand the output I get from four string patterns, which I've labeled as...

View Article
Browsing latest articles
Browse All 201 View Live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>