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

learn more… | top users | synonyms (2)

11
votes
2answers
303 views

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

Both of the following return True: ...
3
votes
6answers
752 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"}?
4
votes
2answers
196 views

Formatting text through pattern matching

I am trying to format some text based on some patterns. ...
16
votes
2answers
863 views

How do I perform string matching and replacements?

What are, and how do I use Mathematica's string matching and replacement tools?
2
votes
4answers
182 views

Remove anything between () except for ; in a string

A simple question but I can't find the answer. I'm scanning a huge pile of mails and would like to get rid of anything between () in the email adresses since this normally contains just info that ...
6
votes
2answers
260 views

How to choose variables from a list for a function and then use the solution in a subsequent function?

I am trying to calculate heating degree days and cooling degree days and output that information to a table. I am using mathematica's curated data to do this. In text this is what I would like to ...
23
votes
4answers
3k 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 ...
8
votes
1answer
234 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 ...
21
votes
6answers
579 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 ...
11
votes
2answers
223 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 ...
8
votes
2answers
313 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 ...
16
votes
1answer
447 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 ...
17
votes
2answers
2k 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 ...
5
votes
3answers
291 views

Thousands separator (comma) option for NumberString/StringCases?

I've been looking for a way to read numbers that have thousands separators in them: StringCases[" 1142.123 ", Whitespace ~~ NumberString ~~ Whitespace, 1] gives ...
15
votes
4answers
784 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 ...
9
votes
2answers
227 views

Behavior of ImportString in Mathematica

I tried the following commands ...
5
votes
3answers
474 views

Creating word histograms from lists of strings

Consider the following: ...
6
votes
3answers
755 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 ...
12
votes
7answers
670 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". ...
5
votes
2answers
355 views

Custom distance metric for agglomerative clustering in Mathematica

Is it possible to have a custom distance metric defined to determine the distance between two clusters in Agglomerative clustering in Mathematica? I have a 3 dimension data with string values along ...
6
votes
1answer
255 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): ...
12
votes
2answers
325 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 ...
15
votes
2answers
406 views

Unicode-aware string functions?

I've recently discovered that ToUpperCase is quite unreliable on non-ASCII input: ...
-2
votes
1answer
205 views

How to set a rule in pattern matching to change a string from one form to another

I want to define a rule that will change a particular type of string to another form. For example:- a string having ...
22
votes
7answers
983 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 ...
10
votes
2answers
562 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 ...
17
votes
6answers
688 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 ...
4
votes
1answer
284 views

Defining a string based sort function

I'm having a bit of trouble figuring out the right Sort syntax to use on a list of lists. Consider the following list: ...
6
votes
1answer
223 views

How to set up new types for pattern matching strings?

Consider the following toy example: I have a set of language sounds, which I partition into two exclusive subsets, consonants and vowels. I want to set up string patterns for e.g. ...
11
votes
1answer
514 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: ...
7
votes
2answers
174 views
15
votes
2answers
547 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 ...
7
votes
3answers
213 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 ...
9
votes
4answers
396 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 ...
30
votes
6answers
4k 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. ...
6
votes
2answers
456 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 ...
15
votes
7answers
2k 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
5answers
2k 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 ...
7
votes
2answers
272 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 ...
10
votes
2answers
216 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 ...
14
votes
4answers
865 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: ...
23
votes
1answer
582 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 ...