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

learn more… | top users | synonyms (4)

12
votes
2answers
405 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
1answer
318 views

StringReplace, ReplaceAll and Rule interact in a bizarre way

I have the following pair of things: ClearAll[foo, labeledFoo]; labeledFoo = {"FooBarBazQuux", foo}; This works like you'd expect: ...
12
votes
1answer
733 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: ...
12
votes
1answer
206 views

Longest common substring for multiple strings?

I'm looking for a way to get the longest common substring for multiple strings such as {home/dir1/dir2/jmoasd.txt,home/dir1/dir2/ivbnoxcihv.txt,home/dir1/dir2/siuhgiuchv.txt} should yield ...
12
votes
1answer
515 views

How to convert a notebook cell to a string retaining all formatting, colorization of identifiers etc?

I have an opened Mathematica notebook containing several cells. Suppose, I am interested in one of them -- it may contain a complete or incomplete expression (e.g. with syntax errors, highlighted ...
12
votes
0answers
117 views

Can Mathematica convert a RegularExpression into a StringExpression or vice-versa?

I know that Mathematica can perform string comparison using either StringExpression or RegularExpression. Although regular ...
11
votes
7answers
253 views

DateList coupled with String Operations

Through some webscraping, I have the following list: ...
11
votes
5answers
2k views

What is the fastest way to extract a substring from a huge string?

I develop an algorithm to find the most common substrings of a given length n up to a certain distance l in front of a pattern p in a huge sequence S. E.g. I want to find the most common hexamers ...
11
votes
2answers
303 views

How can one represent a string pattern with prohibited substrings?

Say I have the following string: "<hello>something WRONG</hello><hello>something else</hello>" I am trying to find code that works like the ...
11
votes
3answers
358 views

How do I make a string literal without having to escape backslashes?

I'd like to say something like: foo = @"\abc\def\ghi" instead of foo = "\\abc\\def\\ghi" How do I do this? This would ...
11
votes
1answer
1k 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?
11
votes
2answers
251 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
2answers
826 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 ...
10
votes
3answers
417 views

Modifying strings in a list efficiently

I have a list of strings $\{s_1,s_2,\ldots,s_n\}$. I would like to to produce the following list of strings: $$ \{s_1<>1,\ 1<>s_2<>1,\ldots,\ 1<>s_n\} $$ In other words, I want ...
10
votes
4answers
268 views

Convert elements of list to string

how easily can I convert elements of this list to string. If I have output like this: {{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}} And I want something like this: ...
10
votes
5answers
302 views
10
votes
4answers
600 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 ...
10
votes
2answers
244 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
207 views

Convert recursive RegularExpression to StringExpression?

Consider the following expression for matching balanced brackets: ...
10
votes
2answers
326 views

Using Except with strings

Suppose that I have the following sample list, called list: list = {"bBb", "aAa", "aaa"}; Now suppose I want to select the ...
10
votes
2answers
306 views

Mathematica Typing Effect

Here is a Typing Effect in javascript. I could only implement a very simple one: ...
10
votes
2answers
211 views

Unexpected result from StringReplace

The following works as expected. StringReplace["xxxyxz", "x" ~~ _ -> "ww"] "wwwwww" And so does this. ...
10
votes
5answers
240 views

Backquote in string template?

I need to have backquotes in a StringTemplate. For example StringTemplate["``1``"][2] Returns ...
10
votes
1answer
285 views

How to change the font color of a variable in whole input cell

I want to track the occurrence of a particular variable in a code. So the idea is to change its color. Usually I do it in a crude way - convert the code into text and then use ...
10
votes
2answers
224 views

Comparing natural language strings

I have a large spreadsheet with thousands of rows/columns of text. Some are saying essentially the same thing but in different ways. When you enter a natural language question Wolfram Alpha makes a ...
10
votes
3answers
289 views

Mathematica equivalent to Python long raw strings? handling escape characters in packages

I'd like to write the following in plain text .m file in Mathematica, without having to double escape all the Latex commands: ...
9
votes
5answers
914 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
2answers
3k 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 ...
9
votes
2answers
293 views

Behavior of ImportString in Mathematica

I tried the following commands ...
9
votes
1answer
151 views

Naming a pattern changes outcome in StringCases[]

s = "1 2 "; StringCases[s, (n : NumberString ~~ " ") .. ] StringCases[s, (NumberString ~~ " ") .. ] yields ...
9
votes
2answers
618 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 ...
9
votes
1answer
223 views

CSS Selectors for Symbolic XML

Symbolic XML is a convenient way of managing XML in Mathematica, at least for casual use or small tasks. Here and elsewhere you can find examples of XML handling in Mathematica, including XSLT/XPath ...
9
votes
1answer
140 views

Named string patterns in Alternatives, why does it depend on order?

When using the same name for part of patterns inside Alternatives how come it behaves differently for strings than in normal patterns? ...
9
votes
1answer
266 views

Creating a version of SequenceAlignment that accepts patterns

SequenceAlignment seems like a function that is not (yet?) fully integrated into Mathematica. I want a function that accepts general patterns instead. I ...
8
votes
5answers
278 views

String replacement question

If you have a string string="<ALK>ene" and I have a list alk={"meth", "eth", "prop", "but", "pent"}, what function ...
8
votes
3answers
568 views

Finding all sublists or substrings of a given list/string

Given a list or string, how do I get a list of all (contiguous) sublists/substrings? The order is not important. Example for lists: ...
8
votes
5answers
476 views

Splitting strings at lower case characters and numbers

I'm trying to split the strings of chemicals into their elements and numbers. See this example "Fe3O4" will be split into ...
8
votes
5answers
310 views

Generate list of strings from a list of assigned variables

How do I generate a list of strings from a list of assigned variables? Eg. Convert ...
8
votes
3answers
404 views

String matching balanced pairs of braces

I am trying to extract from a string in Mathematica all instances of \newcommand{ABC}{DEF} Where ABC and ...
8
votes
1answer
297 views

Understanding `Paste` and how to get a string from the Clipboard to use with `ImportString`

Trying to work on this question I got distracted by my first naive attempt of copying the data and then typing dat = ImportString[Paste[], "Table"] ...
8
votes
3answers
850 views

How to parse information contained in a file name

I have a set of files containing my data, and the file-names contain relevant information that I would like to extract. What I have is: ...
8
votes
1answer
140 views

How to take all sub-strings in a string that are combinations of specified characters only

"tgtaaaaacaagaaaaacatggaatgtataatactataaataaaaaaagtaggaagaagaaccaaaaca\ aagggcgttttaaagagagacgaat" based on the above string (a DNA sequence) I wish to extract ...
8
votes
1answer
118 views

What kind of pattern should I use with StringCases?

Consider the string str = "ABCaDEFbcABCdefDEF" I'd like to take out all substrings surrounded by the substrings "ABC" and ...
8
votes
1answer
4k 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? ...
8
votes
2answers
564 views

A femme is a wife is a Frau

As can be seen from LanguageData["Properties"] // Multicolumn Mathematica's translation capabilities seem to be very limited. It can translate month names, ...
8
votes
2answers
300 views

How can I use words/letters as pixels in an image?

I'd like to take the text of a novel or whatever and arrange it in a way that forms an image. Essentially recreating these works from Postertext. . I'm mostly looking for ideas regarding a ...
8
votes
1answer
173 views

Simple string pattern crashes kernel

Bug introduced in 6.0 or earlier and fixed in 10.1.0 The following code crashes my Mathematica kernel (v9, MacOS): ...
7
votes
6answers
3k views

Convert a string into a list of numbers

I got the following problem I don't know how to solve or if it's at all possible to solve(I'm quite new to Mathematica and don't have an IT background, so please explain slowly if possible:)) I'm ...
7
votes
3answers
758 views

Creating word histograms from lists of strings

Consider the following: ...
7
votes
4answers
851 views

Caesar's cipher

How can Caesar cipher be implemented? I want to use StringReplace but I don't know how to write the replacement rule to replace the characters with, say, the ...