Questions on the manipulation of String objects in Mathematica, and the functions used for these manipulations.
21
votes
4answers
2k views
Looking for “Longest Common Substring” solution
I'm looking for robust code to solve the "Longest Common Substring" problem. I can just code it up from that description, but I'd thought I'd ask here, first, in case someone knows of an ...
18
votes
5answers
2k views
How do you convert a string containing a number in C scientific notation to a Mathematica number?
Suppose I have a string containing the C-representation of a floating point number, for example
s = "1.23e-5"
and I want to convert this to a Mathematica number. ...
14
votes
2answers
335 views
How do I perform string matching and replacements?
What are, and how do I use Mathematica's string matching and replacement tools?
22
votes
1answer
424 views
Convenient string manipulation
With Mathematica I always feel that strings are "second class citizens." Compared to a language such as PERL one must juggle a lot of code to accomplish the same task.
The available functionality is ...
18
votes
3answers
403 views
How to join two Style[]d strings
Does anyone know whether it is possible to combine\join two styled strings?
That is, while the following code works fine:
omega = "text";
omega<>omega
...
8
votes
2answers
476 views
Convert a string to hex number?
How can I convert a string containing a hex number such as "6b" to a hex digit that mathematica can use to do math with?
I have tried using ...
32
votes
3answers
811 views
Visualizing the difference between two sequences (strings)
I'm trying to develop a way of comparing two sequences (probably originally text, such as text writing or source code, possibly converted to lists). As a familiar example, consider the revisions ...
22
votes
7answers
779 views
Splitting words into specific fragments
I am looking into splitting words into a succession of chemical elements symbols, where possible. For example:
Titanic = Ti Ta Ni C (titanium, tantalum, nickel, carbon)
A word may or may not be ...
20
votes
6answers
383 views
Partition string into chunks
This seems like it should be trivial, but how do I partition a string into length n substrings? I can of course write something like
...
9
votes
3answers
258 views
How to remove accents from text?
I would like to know how I can remove accents from a string. For example, how can I transform "string test áéíóú" into ...
8
votes
3answers
182 views
balanced Shortest[] and string-patterns
The pattern Shortest["A"~~__~~"B"] is oriented : It assumes the text is read from links to right and it takes the text between the first "A" and the next "B".
Any ...
7
votes
2answers
188 views
Revert FullForm-ed text to prettyprinted
Sometimes strings in a notebook/package file end up garbled due to some unknown/unintentional conversion of the expression/cell/notebook. I could not find a way to revert such unreadable text to its ...
6
votes
2answers
368 views
How to overload System`StringJoin to automatically use ToString on arguments?
I am using an overloaded version of the StringJoin function since years now, without any problem, as I've invested a lot of time and effort earlier to make its ...
12
votes
2answers
651 views
How to import all files of a folder at once?
I know how to import one textfile by calling its name
filestring = Import["myfile.tex", "Text"];
Then "filestring" is a string with the myfile content.
How do ...
14
votes
6answers
383 views
Splitting a list by specifying section headers
I have a list of strings called mylist:
mylist = {"[a]", "a", "a", "[b]", "b", "b", "[ c ]", "c", "c"};
I would like to split ...
16
votes
6answers
524 views
Split a string at specific positions
Given a string of alphanumerical characters, how to split it simply and quickly at the center of continuous letter-substrings? Is there an elegant and fast solutions out there in the "computational ...
13
votes
2answers
243 views
Unicode-aware string functions?
I've recently discovered that ToUpperCase is quite unreliable on non-ASCII input:
...
13
votes
2answers
312 views
Lexicographic ordering of strings in Mathematica
I recently realized that Mathematica seems incapable of comparing strings in the "normal" expected lexicographic order. Indeed, for some simulations, I need to process text directly, without fiddling ...
3
votes
2answers
165 views
Highlighting text with StringReplacePart but also using Style, Subscript
For a Natural Language Processing analysis task it's desirable to highlight a text string programmatically according to XML tags that reference specific words or phrases.
The XML tags specify the ...
2
votes
4answers
129 views
How to write a function to remove comments from a .m source file preserving formatting such as line wrapping reasonably?
How to write a function to remove comments from a .m source file preserving formatting such as line wrapping reasonably?
This means if I have
...
11
votes
7answers
356 views
DeleteCases on list of Strings
Consider the following:
data={"AB","CD","AF"};
Now I would like to delete all String from data which starts with "A".
...
11
votes
3answers
378 views
Converting a large floating-point number to a single-line string
When I feed a large (or small) enough floating-point number to ToString, it produces a two-line string, with the first line containing only the exponent of 10:
...
5
votes
2answers
169 views
Concatenate strings from different levels of list
After a lot of trouble I've finally come pretty close to what I want to do. I now have a list that looks like this:
...
4
votes
6answers
290 views
Getting a String from a list of strings
Is there a way to write down Mathematica with a string such as:
{"M","a","t","h","e","m","a","t","i","c","a"}?
3
votes
1answer
96 views
String replacement to make the TeXForm output beautiful
This question is inspired by this question: How to convert the symbol $d$ in Integrate into $\mathrm{d}$?.
Although it’s not a big problem, the TeXForm can be ...
3
votes
3answers
192 views
Converting a string containing whitespace-delimited numbers to a list of numbers
Suppose I have a string str that contains only whitespace-delimited real numbers:
...





