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

learn more… | top users | synonyms (3)

11
votes
2answers
242 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
419 views

Should I use \\\“ or \” to match " in regex?

Both of the following return True: ...
11
votes
2answers
739 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 ...
11
votes
1answer
416 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 ...
10
votes
3answers
364 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
510 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
230 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
3answers
273 views

balanced Shortest[] and string-patterns

The pattern Shortest["A"~~__~~"B"] is oriented : It assumes the text is read from left to right and it takes the text between the first "A" and the next "B". Any ...
10
votes
2answers
301 views

Mathematica Typing Effect

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

Unexpected result from StringReplace

The following works as expected. StringReplace["xxxyxz", "x" ~~ _ -> "ww"] "wwwwww" And so does this. ...
10
votes
1answer
891 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?
10
votes
3answers
188 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 ...
10
votes
2answers
160 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 ...
9
votes
5answers
831 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
263 views

Behavior of ImportString in Mathematica

I tried the following commands ...
9
votes
2answers
2k 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
1answer
131 views

Naming a pattern changes outcome in StringCases[]

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

Convert recursive RegularExpression to StringExpression?

Consider the following expression for matching balanced brackets: ...
9
votes
2answers
231 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 ...
9
votes
3answers
236 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
1answer
134 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
261 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
267 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
420 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
159 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 ...
8
votes
1answer
167 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 ...
8
votes
2answers
558 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
1answer
161 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
5answers
423 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 ...
7
votes
3answers
650 views

Creating word histograms from lists of strings

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

Strange answer from StringReplace

I have a list of strings and I would check if there is an empty string element, that's "", because I need to replace it with a "0". I try the following ...
7
votes
5answers
217 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 ...
7
votes
1answer
225 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"] ...
7
votes
3answers
183 views

Converting StringJoin to StringForm inside Hold

Let's say I have a piece of code: Hold[{code1, "asdad " <> ToString[testa] <> " adsd " <> ToString[testb], code2}] (*MWE ofc*) ...
7
votes
1answer
3k 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
2answers
201 views
7
votes
3answers
239 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
1answer
147 views

LetterCharacter for Cyrillic symbols

Why does the code StringMatchQ["ы", LetterCharacter] return False? Probably because: ...
7
votes
2answers
331 views

Converting a string into a nested list of strings

The following string can be converted easily into a list with ToExpression ...
7
votes
1answer
165 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 ...
7
votes
2answers
348 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 ...
7
votes
1answer
271 views

Dataset and string conversion, using Internal`StringToDouble

i'm trying to get familiar with the new Dataset-stuff in Mathematica 10. As it will (hopefully) provide some benefit for me, I have started to convert my app to move from list and list of rules to ...
7
votes
2answers
96 views

Strange Error on Fresh Kernel (10.2)

Bug introduced in 10.1 I wrote a helper function to format real numbers in a certain format for writing .dbf files here. It relies on a new function to 10.1 - ...
6
votes
4answers
298 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
6answers
2k 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 ...
6
votes
3answers
374 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: ...
6
votes
2answers
526 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
341 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 ...
6
votes
3answers
506 views

Camel hump string split

Given System names of 2 or more characters: systemNames = Names["System`*"] // Select[StringLength[#] > 1 &] ; Is ...