Questions on the manipulation of String objects in Mathematica, and the functions used for these manipulations.
32
votes
3answers
809 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 ...
23
votes
4answers
846 views
What is the fastest way to count square-free words?
Background
A word is a string of letters in an alphabet. A square-free word has no adjacent repeating substring. For example, (in the ternary alphabet of {0,1,2}) the words 00, 012121, and 0212012021 ...
22
votes
7answers
778 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 ...
22
votes
1answer
423 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 ...
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 ...
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
...
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. ...
18
votes
3answers
400 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
...
16
votes
6answers
523 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 ...
15
votes
4answers
482 views
Finding all dictionary words that can be made with a given set of characters (Wordfeud/Scrabble)
This is a slightly more involved variant of this recent question. By sheer coincidence I happened to have been building a Wordfeud (Scrabble clone) game in Mathematica.
My interactive Wordfeud ...
15
votes
1answer
328 views
NotebookFind and String Pattern Expressions
Is there a way that NotebookFind can be used to match string pattern expressions rather than just strings?
The documentation for ...
14
votes
7answers
1k views
How to express an integer number in English words?
How do I convert a number to a readable string?
I would like to implement a function, inWords[],
inWords[n_]:= ?
which ...
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 ...
14
votes
3answers
399 views
Grabbing a number of characters around a string pattern
If I have some string data:
text = StringTake[ExampleData[{"Text", "DeclarationOfIndependence"}], 400]
"When in the Course of human events, it becomes ...
14
votes
2answers
334 views
How do I perform string matching and replacements?
What are, and how do I use Mathematica's string matching and replacement tools?
14
votes
2answers
199 views
Haiku Extractor
Inspired by the cool Tumblr Haiku Times that searches for accidental haiku in New York Times articles, I tried my hand at implementing such a search in Mathematica for my own text samples.
I'm still ...
13
votes
4answers
884 views
sprintf() or close equivalent, or re-implementation?
Is there a sprintf() command (some command that takes a printf-style format string and a list of values to insert into the ...
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
310 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 ...
12
votes
2answers
226 views
Split a Unicode string maintaining uppercase characters
I want to split a string according to a predefined set of substrings (lowercase), though the actual text can contain uppercase characters anyplace. The task is to find the matches, longer preferred ...
12
votes
2answers
649 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 ...
11
votes
3answers
377 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:
...
11
votes
2answers
188 views
Pasting “rectangles” of text side-by-side
In Emacs/Xemacs, there is a rectangle feature, such that you can delete, copy, etc., "rectangles" of text.
Now suppose I have two text files, each containing one column of numbers. Is it possible to ...
11
votes
1answer
289 views
Rearranging a Polynomial
In Mathematica 8.04 on Windows, I want to display a formula in standard textbook format. The formula is the variance of an $N$-security portfolio. For two securities it is:
...
11
votes
2answers
173 views
10
votes
7answers
353 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".
...
10
votes
7answers
175 views
10
votes
2answers
192 views
What's a robust way to insert another extension into a filename?
I'd like to add an extension to a filename before the file extension, otherwise leaving the given filename the same. In particular, absolute filenames should stay absolute, and relative filenames ...
10
votes
2answers
256 views
Mathematica Typing Effect
Here is a Typing Effect in javascript.
I could only implement a very simple one:
...
10
votes
1answer
153 views
Mathematica equivalent of regex '\w{2,3}'
It beats me to write the Mathematica pattern equivalent to the regex:
\w{2,3}
Any ideas?
9
votes
5answers
365 views
convert long string to integer list
at first, i would like to thank all the people here. i'm working with mathematica for half a year now and always found great advice and tricks.
now, i came up with a problem i couldn't find a ...
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 ...
9
votes
2answers
342 views
How to get string representation (like repr in Python)
I have a string variable. I want to obtain another string which contains the representation of the string variable content itself.
s = "a \n b"
I need to get a ...
9
votes
2answers
193 views
Transform fancy usage messages in 1D string
When we look at the usage messages of built-in functions nowadays (not in the good old times, when they were a simple descriptions) we see that although they look pretty in the front end, it is really ...
8
votes
6answers
316 views
How do I extract a number from a string?
I want to extract the number from an alphanumeric string. This is what I tried:
StringTake["thiru3", {6, 6}]
The result I got is ...
8
votes
2answers
162 views
8
votes
2answers
475 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 ...
8
votes
2answers
165 views
Keeping Quotation Marks in Output
I am running into the following seemingly simple problem. I have this code:
testphrase="i love you";
input=ToLowerCase[StringSplit[testphrase, Whitespace]]
It ...
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
3answers
259 views
How does string interpolation work in Mathematica
I've noticed that Mathematica 8 seems to have some kind of string interpolation feature, but I couldn't find any documentation on it and I can't figure out how it works.
For example, if I enter
...
7
votes
1answer
166 views
What pattern will match accented letters in a regular expression?
How should I modify the following such that the accented letter É is matched and the expression returns True?
...
7
votes
3answers
184 views
How to turn a set of strings which represent a list into a 2D list
I have a set of data read in from a larger CSV file. I want it to match the format I have from another analysis. It is structured as a series of strings with letters and numbers Here it is copy-pasted ...
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
4answers
239 views
Where can I take a pool of words from?
Dear Community members,
I am thinking about an interactive machine to teach a school child to write difficult words correctly. As a first step I need a collection of words. I will select a pool of ...
6
votes
2answers
366 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 ...
6
votes
3answers
271 views
Specifying string patterns in DeleteCases
It seems that DeleteCases is not compatible with string patterns, at least directly (see, for example, this question). Is this true? If so, why is this the case? ...
6
votes
3answers
238 views
print the name of the variable in a list without evaluation
a := az + 1
b := bz + 5
list := {a, b}
I'd like mathematica to print
a = az + 1
b = bz + 5
so basically it needs to first ...
6
votes
3answers
122 views
Importing and manipulating strings - time data
I have a list of time durations, which are strings of the form: "hh:mm:ss". Here's a sample for you to play with:
...
6
votes
2answers
132 views
Why is StringMatchQ[“IP1”, “IP”] returning False?
Maybe there is a knot in my head, but I would expect that
StringMatchQ["IP1", "IP"]
should return True (which it does not) ...
6
votes
1answer
150 views
Interpreting text entry and splitting it in a Manipulate text field?
I have the following program that plots the number of trigram appearances across a corpus of textual information between 1964 and 1989 (apologies for the messy code):
...





