Questions tagged [string-manipulation]

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

Filter by
Sorted by
Tagged with
7
votes
4answers
28 views

How can one convert an expression to a string while keeping the quotation marks of strings that are part of the expression?

How can I for example convert {"a","b"} to "{\"a\",\"b\"}", so keeping the quotations marks.? I tried ...
0
votes
0answers
23 views

Import txt file in Mathematica as vector array [on hold]

i have a .txt file of two colums and 30 lines. I would like to import it in mathematica as an array of two colums and 30 lines in order to be able to use this number in my simulations.
0
votes
1answer
43 views

How can import more files simultaneously and clean them in Mathematica?

I would like to import three files in Mathematica (I am using the Import function[]) and try to clean them. I used ...
0
votes
0answers
30 views

relating Compress[] to information theory

I have a question regarding the Compress[] function. From my reading, Compress[] is based on zlib and should provide lossless compression. Given a string (call it test), I would expect that, from ...
1
vote
1answer
77 views

Defining functions from strings

Blank symbol (_) is moved when applying ToExpression to the following string: ...
1
vote
0answers
49 views

How can I handle box drawing characters?

I must generate files for windows batch scripting, modifying template files, es. ...
0
votes
1answer
78 views

How many symmetric words are in a string? [closed]

Determine how many symmetric words are in a given string. https://reference.wolfram.com/language/tutorial/WorkingWithStringPatterns.html
0
votes
1answer
46 views

ToExpression[ToString[x^2]] does not produce x^2 [closed]

ToExpression[ToString[x^2]] does not produce $x^2$, instead it gives $x$. Please explain. I actually wrote the following code and it gave the answer as 1. ...
3
votes
1answer
32 views

How to remove the trailing ` in StringForm[“Mean `1`”, 2.2]?

How to remove the trailing ` in the following? StringForm["Mean `1`", 2.2] produces Mean 2.2`
0
votes
0answers
68 views

Strip of all tags “Defer[…]” from a string expression

How can i remove all "Defer[...]" from the following expression ...
0
votes
1answer
47 views

Delete elements form a list with elements with strings and numbers

I am trying to create a list list2 removing elements from a list list. The structure of list...
2
votes
1answer
42 views

Using StringTemplate with TableForm [closed]

I have a table given by ...
1
vote
1answer
46 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
1answer
26 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
50 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
407 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
54 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
26 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
45 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
35 views

Text with dynamic values

...
5
votes
3answers
543 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
34 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
71 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
82 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
50 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
41 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
236 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
27 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
71 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
72 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
843 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
52 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
154 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
33 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
54 views

comparing lists of strings

I have two lists of strings like this: ...
0
votes
2answers
64 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
304 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
80 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
63 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
56 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
114 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
72 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
49 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
50 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
109 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
45 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
186 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 ...