Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [string-manipulation]

Questions on the manipulation of String objects in Mathematica, and the functions used for these manipulations.

2
votes
1answer
49 views

Web Scraping - Why are these numbers interpreted as strings?

I started with: data = Import["https://www.destatis.de/DE/ZahlenFakten/GesellschaftStaat/Gesundheit/Todesursachen/Tabellen/Sterbefaelle_Unfaelle.html", "Data"] ...
4
votes
2answers
148 views

Commonest[] function doesn't actually show commonest elements

I'm using Commonest function on a list with 500000 words to get the 10 most frequent elements. Then by using WordCloud, I found ...
1
vote
1answer
28 views

Line break a long expression only at whitespace

Suppose I have some long string expression. I want to break this into multiple lines,with an ampersand at the end of each line. My first attempt was of the form, ...
1
vote
1answer
38 views

comparing lists of strings

I have two lists of strings like this: ...
0
votes
2answers
51 views

Replacing all integers in a string

Let's say I have some expression like, expr = 1*a + 2*b +3*c + 4*d I want to write this to a string that I can then use in some other Fortran script. I want all ...
2
votes
1answer
292 views

How can I get the count of how many times a string appears in my list? [closed]

I have a list of strings, like so: {"aa bb", "cc dd", "aa bb", "aa bb", "cc dd", "ww ss", "ss ss", "kk mm"} I know WordCounts ...
4
votes
2answers
71 views

Partitioning string into longest substrings of given characters

I want to partition string into longest substrings that each contain only specific characters, beginning from left to right with no overlaps, always choosing the longest one possible at current ...
1
vote
2answers
59 views

Find the position of letter i in a list of words

I want to find the position of letter i in each word of a text. Take their positions and then sum them up. Example, in simplicity, the score will be 2+6+8=16. In this way, I calculate the score for ...
0
votes
2answers
44 views

Creating a table in a while loop

I am probably missing something obvious, but I am stuck. I am writing a code on Mathematica for Newton's method, and I need to print out a table for the iteration, approximation root, residual, and ...
3
votes
2answers
103 views

Print integer number fraction as string of numerator and denominator

I want to convert an integer number fraction as text with a certain font, size and color: Example: ...
0
votes
0answers
27 views

Preventing single letter italics within a string [duplicate]

I want to be able to use super/sub scripts without the main character being forced in to Mathematica's math italics mode. The motivation being to preserve the font style settings on the string in ...
1
vote
2answers
70 views

How can I extract blocks of 8 bits data from a plain text file?

I have a plain textfile consisting of 4M numbers (0 and 1's) from the number Pi. I would like to split this textfile into blocks of 8 bits (ie 8 characters). I know this can be done with StringTake ...
0
votes
1answer
39 views

Suppressing DateString default behavior when parts of date are missing

By subsampling data from a Excel spreadsheet I have created a Mathematica dataset that I then seek to modify by applying various functions to the fields to convert these data into a different flat ...
3
votes
1answer
43 views

String Pattern to match “x by y”

I'm trying to create a string pattern which will match either (with quotes included): "x by y" x by y 'x by y' I've tried to use the following pattern: ...
4
votes
2answers
102 views

Deleting unwanted elements in lists of words

I have imported Alice in Wonderland into Mathematica. I have made a list of the sentences and further divided them into words. Now suppose, nominally, I have the following list: ...
1
vote
1answer
39 views

Deleting all whitespace in mathematica expression

I have copied and pasted some output from a .log file into a mathematica notebook however the resulting output in the notebook contains many whitespaces between lines. Is there a way to eliminate ...
3
votes
3answers
135 views

Selecting elements from lists based on string pattern

I have a list: lis = {{"abc", 1, 2}, {"cde", 3, 4}, {"fgbc", 5, 6}} I would like to select list items that have first elements that end in the string "bc" to ...
0
votes
0answers
11 views

Transform String to Expression [duplicate]

I have a variable postVector and another called CHKpostVector. Both are global variables. Only the variable ...
0
votes
0answers
42 views

Ignoring text when converting strings of text to numbers

I have a string of measurements--mostly numbers, but occasionally an NA. Right now Mathematica is reading it all as text, so I'm using ...
2
votes
1answer
156 views

Interpreting Mathematica code on black holes

I am trying to understand the code written down on page 7 of this document (code is in Mathematica) I understand pretty much all of the code on the previous page needed to setup the page 7 code (...
0
votes
1answer
51 views

Modification to the list of string

Suppose we have a list of the following: l={"applejuice","lemon_juiceginger"} How can one modifies this to read as: ...
5
votes
3answers
74 views

StartOfLine and EndOfLine not working well inside Shortest

Suppose that I want to replace lines containing "b" with a new "XXX" line. This works as expected with regular expressions: ...
2
votes
1answer
46 views

DateObject ambiguous string interpretation?

I try to enter the following input, but receive an error message: DateObject["12/1/2016", DateFormat -> {"Month", "/", "Day", "/", "Year"}] despite having ...
1
vote
3answers
60 views

Manipulation of two lists of strings and integers

I have the following lists: ...
5
votes
1answer
77 views

Complicated formatting of a string list

I have the following list: ...
0
votes
1answer
43 views

Convert string representation of matrix to matrix

I have a Python script which generates and outputs Mathematica matrices. I use RunProcess to run my Python script and I extract the StandardOutput which is the Mathematica matrix as a string. What I ...
1
vote
0answers
27 views

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 ...
5
votes
2answers
60 views

FileNames not containing a given extension

I would like to get all the files in a directory without a given extension. To get them with that extension is quite simple: FileNames["*.<myExt>", myDir] ...
0
votes
1answer
45 views

Convert number to list [closed]

FromDigits will convert a list to a number, i.e. FromDigits[{5, 1, 2, 8}] > 5128 Now, I want to convert ...
2
votes
1answer
54 views

Have a String of letters with different font sizes - LineLegend

There's a Plot whose legend has symbols with subscripts and regular text. The words that have subscripts appear to shrink in size and looks out of place in comparison to the rest of the legend. Was ...
3
votes
3answers
104 views

Convert Latin to e.g Gothic

Sorry for the very simple question but I can't seem to find an answer anywhere. I have a list of Latin letters, e.g. {a, b, c, d...}. I want to convert them to the corresponding Gothic letters. How ...
4
votes
1answer
52 views

Longest Repeated Substring

Is there a solution in Mathematica to the problem of finding the longest substring of a sequence that occurs at least twice.For example {1, 2, 3, 4, 5, 2, 3} has ...
2
votes
1answer
65 views

How to Text justify that includes StringSplit and MapAt in it?

I am preparing a practical class of physics in which I need to justify the following text that is very extensive. But when I use StringSplit or ...
4
votes
1answer
75 views

String Join but not fully

Suppose I have the following string list: l={{"a","dog"},{"the","pen"}} how can I turn this to {{"a dog"},{"the pen"}} I ...
0
votes
1answer
38 views

StringSplit with SubscriptBox

My code has a problem ...
3
votes
2answers
76 views

Having Mathematica replace DOS line breaks with UNIX in files

Say I have a file named "Silly.tex" which has \r\n line breaks. Is there a way to get Mathematica to convert it to only have \n line breaks? You can find such a file with DOS line breaks at: https://...
3
votes
1answer
65 views

How to change node color in .dot file using pattern matching?

For example I have a dot file that describe a decision tree or binary tree In the file, the color of node is always gold, so I try to change it according the number in ...
5
votes
2answers
219 views

Rearrangement of lists of strings

I have a list: lis = {{"abc","def","ghi"},{"jkl","mno"}} and wish to get: res = {"abc def ghi","jkl mno"} This: ...
2
votes
1answer
61 views

How to write single slash in string programmatically

Consider the function: unicode[numericLetters_List]:=StringJoin@Reverse@Cases[numericLetters,x_:>If[x!=" ","\:"<>x,x]]; now ...
1
vote
1answer
57 views

Resolution of string lists to smaller components II

Some weeks ago, I posted a question which involved creating string pairs from a list of string elements. One of the answers posted (by Kuba) worked very well until I found an example where it didn't. ...
1
vote
3answers
89 views

Finding the frequency of letters in a string

Given the following string: ...
2
votes
1answer
56 views

How to refer to a character group without ambiguity in a regex?

Suppose I want to realize a replacement in a string: "aabbcc11dd ee" -> "aabbcc112dd ee", I can use a regex like this within ...
1
vote
1answer
47 views

Selecting elements using two lists

I made the following list: ...
2
votes
1answer
42 views

Logically equivalent Through expressions, but one produces an error

I have a list of three lists of strings. Thus, MatchQ[{{__String}, {__String}, {__String}}] is True. I would like to extract all ...
7
votes
4answers
751 views

Add a space after a ending dot of a sentence

How can I add a space after the ending dot of a sentence? So dots like in "1.2" should be unaffected. Also if there is already a space, then there should not be a ...
4
votes
1answer
243 views

Delete all French stopwords [duplicate]

I have a list of french stopwords: ...
7
votes
1answer
440 views

A strange verb from Mathematica's WordList

The first word returned by WordList["Verb"] is "aah", even though I think it actually an interjection, I still wonder whether ...
3
votes
2answers
128 views

Merge associations with the same keys, same in a sense by user's definition

I know that it is the standard functionality of Merge to combine the values of the same keys among associations. Now I would like to deal with a situation in which,...
5
votes
2answers
153 views

Convert Unicode to Math Input

Any Ideas how I could convert unicode to Mathematica Input ? For instance : I have the following Unicode: test= {"a", "\\:1d62"} So here I would like to convert ...
2
votes
1answer
92 views

Convert ASCII Characters to Mathematica Input Form

I have the following pure ASCII character list: ...