Questions on the manipulation of String objects in Mathematica, and the functions used for these manipulations.
23
votes
4answers
848 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 ...
4
votes
3answers
98 views
Find the position of a string element, knowing only part of the string
I have a list, e.g.:
list = {1, 2, 3, "Element 1", 4, 5, "Element 2", "Something else 1", "etcetera"}
Now, I want all elements starting with ...
6
votes
1answer
88 views
How does `LongestCommonSubsequence` work?
When I recently came across this posting about LongestCommonSubsequence I was curious about how the function worked.
...
3
votes
1answer
95 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 ...
0
votes
0answers
76 views
How to highlight a string pattern? [duplicate]
This is an example in the help pages (Working with patterns: Highlight Patterns):
...
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?
32
votes
3answers
810 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 ...
1
vote
2answers
80 views
Image processing - How can I apply an operation to several images at once?
I imported pictures into Mathematica, and used names for them that follow the easy scheme "name" string joined with an integer, ranging from 14 to 20. Printing these images on screen works nicely:
...
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 ...
0
votes
2answers
81 views
help with StringJoin [duplicate]
dollarWon := 100
"(" <> Style["$" <> ToString[dollarWon], If[dollarWon >= 0, Darker[Green], Red]] <> ")"
I am getting an error: String ...
5
votes
2answers
85 views
How to count words in a Greek text
I want to perform a simple analysis of some Greek text: collect the different words used and count their frequency. It seems that some of the built-in commands do not work well with Greek letters. For ...
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 ...
1
vote
2answers
48 views
How to convert TableForm to proper LaTex and why is “\” not replaced by StringReplace?
I'm trying to optimize the teXForm output of a table because the standard output ist not satisfying:
...
11
votes
1answer
290 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:
...
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 ...
3
votes
3answers
328 views
Parameters in plot titles
My issue is how to mix strings with variables, specifically in the context of PlotLabel:
I can put a string as my plot title, and I can also put a variable as a ...
2
votes
2answers
89 views
5
votes
3answers
110 views
Unencoding encoded URLs in a function
Is there a built-in function for decoding encoded URLs in Mathematica?
I would like to convert an encoded URL, for example
...
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 ...
1
vote
2answers
108 views
Finding strings in Web Code [duplicate]
I haven't found an answer that solves my problem, although I think it's actually a simple one. It seems hard to me because I don't have a lot of experience with string patterns.
I have a Web Code ...
0
votes
1answer
58 views
Construct file names using a number and a string prefix [duplicate]
I'm trying to append filenames with Mathematica, and cannot do it.
The output of my calculation are two lists : X and Y, ...
-4
votes
2answers
88 views
how can i convert data into string format? [duplicate]
I have nested-lists in number format,like
data={{1,2,3},{2,{3,4,50}},{4,5,6},{3,{3,{5,6}}}}
I want to convert each number into ...
4
votes
1answer
71 views
Extracting text from cells, preserving non-ASCII characters
Consider the following setup, based on this answer by WReach:
...
0
votes
1answer
111 views
How do I construct a “named character” programmatically?
Why am I getting the error
Syntax::sntunc: Unicode longname in the string is unterminated.
from the following?
...
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
...
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 ...
1
vote
2answers
108 views
Why do I get two different results from StringLength?
I spent a reasonable amount of time to find the origin of an error in a larger code segment.
...
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 ...
1
vote
2answers
166 views
Faster way to convert real strings into numbers [duplicate]
Working with big files, I have to convert some numbers that are in string format into real MMA numbers. I know that I can use ToExpression but it's slow when ...
0
votes
3answers
120 views
How to export a header before the data in the result file?
I would like to export a phrase to my result data as a heading.
I'm exporting the data correctly with
Export["file.dat", table].
But I'm doing several ...
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
...
2
votes
3answers
224 views
How to extract a consecutive list of substring from a string?
Given a list of strings:
data = {
"2894;Hot Pink;53:09:44;1449714",
"17456;Dark Cyan;19:06:42;6929227",
"5147;Lime;54:11:55;5247632"
}
(Words are separated by ...
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?
...
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:
...
2
votes
1answer
90 views
Confused behavior using Dispatch to sort one list relative to another
I have a need to sort the entries of one list into the same sequence as the entries in a reference list. Because I have rather large lists involving strings, I'm trying to use Dispatch to accomplish ...
1
vote
1answer
148 views
Renaming files of form FileName(i).csv to NewNamej(k).csv where j increments and k resets to 1 when there is a jump in i?
Edit up top: The accepted answer works splendidly except I had to add //ToExpression to the end of the definition of ns given by ...
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 ...
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 ...
3
votes
0answers
82 views
Unicode beyond Basic Multilingual Plane
String manipulation takes a dive when characters beyond \:FFFF are used e.g. Mathematical Alphanumeric Symbols. The characters display fine but doing string ...
4
votes
2answers
88 views
How can I know if a pattern corresponds to a string pattern?
What would be the best way to detect if a pattern corresponds to a string pattern ?
An invalid string pattern p would lead to an error in ...
10
votes
2answers
257 views
Mathematica Typing Effect
Here is a Typing Effect in javascript.
I could only implement a very simple one:
...
4
votes
1answer
78 views
Strange behavior of DateList when converting string
DateList experiences some strange behavior which i cannot explain.
This code works fine:
...
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 ...
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 ...
13
votes
4answers
885 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 ...
3
votes
2answers
98 views
Import[] exception possibly caused by ToString[] behaviour which I cannot explain
Let me just start by pointing out I'm a new StackExchange user as well as a new Mathematica user (started today!) I mention this as a context to my ineptitude :)
I am attempting to read through a ...
4
votes
1answer
48 views
2
votes
1answer
79 views
ToString in a function
f[x2_] = ToExpression[StringTake[ToString[x2], -1]] x2;
f[a3]
(*Out: 2 a3*)
I expected the output to be 3 a3, but apparently ...
4
votes
2answers
154 views
Split string into sub-strings of length n [duplicate]
Possible Duplicate:
Partition string into chunks
How can I split a string into sub strings of length n? For example I have a string
"ABCDEabcde1234"
...
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 ...





