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.

1
vote
1answer
26 views

Using StringTemplate with TableForm

I have a table given by ...
1
vote
1answer
38 views

Change date format for different variants of SQL

Wrote this code to change MS Access variant of SQL date format to T-SQL, basically recognize dates delimited with pounds and change pounds to single quotes My Mathematica code is Pythonic, because I ...
0
votes
0answers
31 views

Counting number of words in a Wikipedia article [closed]

I tried using the command Total[TextWords[WikipediaData["computer"]]] but it didn't work. Why?
0
votes
1answer
23 views

Count the number of words in WordList that start with a “q” [closed]

How can I create a subset of WordList[] that contains only the words that start with "g"?
1
vote
1answer
39 views

How to encode the character into UTF-8?

As we know the café is caf\xc3\xa9 after encode by UTF8: >>> 'café'.encode('utf8') ...
6
votes
2answers
385 views

Convert a huge txt-file into a dataset

My friend has this huge txt-log of sea levels. He wants to organize it into a dataset. After importing it this file a used StringSplit to separate it into rows, then to singular elements ...
1
vote
1answer
42 views

Function returning a pattern with condition - how to prevent condition to evaluate prematurely?

I figured it would be convenient to have a function that returns a pattern, that match equally nested brackets, of the specified type. Such a pattern is easy to create, but I get some error messages, ...
0
votes
0answers
25 views

How to join words in a list to form a single sentence? [duplicate]

If I have a list of words such as: {"If","I","have","a","list","words","such","as"} How can I join all the words in this list and for a single string sentence ...
-3
votes
1answer
42 views

Performing loop operation (average on lists of datas) of strings of datas [closed]

Lets say I have 100 CSV files of two columns data in each file, and I want to calculate the average of the 2nd column of each CSV file and then save all all these 100 averaged values in one CSV file (...
0
votes
0answers
34 views
5
votes
3answers
534 views

Delete strings: {name, John, John Doe, Doe} to {name, John Doe}

I am not very familiar with coding and I am trying to solve the following: Input: {name, John, John Doe, Doe} Output: ...
0
votes
1answer
27 views

Extract substring: knowing the starting characters and form

I'm trying to extract a specific part of a long string, where the part of interest starts with "testx" and ends with a number before an underscore follows, so e.g., ...
3
votes
2answers
65 views

Function to join variable names

I am trying to define a function that takes any two strings (possibly predefined as variables, functions, etc.) and join them in one string (which can also be predefined and will keep its definition ...
5
votes
2answers
81 views

Sub-subscripts in strings cause different spacings than subscripts

Spacing around subscripts within strings seems to work well: But the spacing around sub-subscripts does not: I did not manually add that space after the 2. How can this be fixed? Thanks!
3
votes
1answer
47 views

Fixing different display colors within string

My question below is my attempt to reduce a problem I am having to the simplest possible version that will show the error I am trying to fix. I recognize that the coding looks tortured, and I will ...
2
votes
0answers
38 views

Bug with TeXForm conversion of superscript in strings [duplicate]

Bug introduced in 10.0 or earlier and persisting through 11.3 Consider a String expression with a TemplateBox superscript: ...
3
votes
1answer
232 views

“Riffle” two strings

I have two strings, e.g., s1="A|P|Q|Z" and s2="r|ss|t|yy", where "|" is meant to be a ...
2
votes
1answer
26 views

How to count the number of characters seperated by a special character in a string?

I have a string in which a special character is treated as the separator. For example, str={aA|B|b|Ca|XYzz}, where "|" is the ...
1
vote
1answer
68 views

How to generate letters for multiple people from a list of names

I need to generate many letters of invitation from a list of people. I thought this would be already asked/answered in this forum, but I can't find anything useful. Basically, I need to write a letter ...
0
votes
2answers
61 views

Comparing strings within a list of strings

I have a single list containing strings like this: list={"house", "cat", "dog" ,"horse", "horses", "tree"}; How can I compare these strings within a list and ...
4
votes
3answers
723 views

Create all possible words using a set or letters

Given a list of letters, letters = { "A", "B", ..., "F" } is it possible to get Mathematica to generate all ‘words’ (in this example, 6 letter words), if only ...
2
votes
1answer
51 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
149 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
31 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, ...
2
votes
1answer
49 views

comparing lists of strings

I have two lists of strings like this: ...
0
votes
2answers
62 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
301 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
75 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
62 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
50 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
110 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
28 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
71 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
46 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 ...
4
votes
1answer
49 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
104 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
41 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
163 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
43 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 ...
0
votes
1answer
52 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
75 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
73 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
61 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
48 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
28 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
65 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
49 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
59 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 ...