Tagged Questions

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

learn more… | top users | synonyms (2)

14
votes
6answers
460 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 ...
2
votes
1answer
118 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
3answers
2k 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 ...
4
votes
2answers
581 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" ...
6
votes
3answers
260 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: ...
8
votes
2answers
1k 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 ...
23
votes
3answers
1k 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 ...
3
votes
3answers
493 views

Converting a string containing whitespace-delimited numbers to a list of numbers

Suppose I have a string str that contains only whitespace-delimited real numbers: ...
0
votes
1answer
337 views

StringJoin/FileNameJoin doesn't quite work in script

My mathematica script is as follows: ...
6
votes
2answers
144 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) ...
23
votes
4answers
1k 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 ...
5
votes
5answers
455 views

Extracting columns of text from a rectangular string

I have very large rectangular strings (on the order of 30-100 MB in size), which I import into Mathematica from text files using a command like ...
15
votes
3answers
442 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 ...
8
votes
3answers
545 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? ...
3
votes
3answers
121 views

Using NumberString, DigitCharacter, or a similar directive to find all string representations of integers in a string

I have a text file containing many, many lines of text like test in the following: ...
3
votes
5answers
307 views

How to extract strings from the list with an additional condition on previous elements?

There are a long list of strings $s$ and two lists of substrings $s1$ and $s2$. I want to take all elements of $s$ which contain a substring from $s2$ and such that before it on no more than $n$ ...
11
votes
7answers
214 views

DateList coupled with String Operations

Through some webscraping, I have the following list: ...
5
votes
3answers
171 views

DateList's aggressive interpretation of TimeML duration codes

DateList "aggressively" interprets strings, such as "p72h": DateList["p72h"] gives ...
5
votes
1answer
285 views

import complete date string to mathematica

Based on an example from here I try to parse dates from a table including the time, but it fails. This is the modified example: ...
4
votes
4answers
577 views

Creating lists from a string, separating words from numbers

Say I have a string that contains numbers and words, such as this one: string = "there are 1234 words and numbers 5678 in here $999"; How would I separate the ...
5
votes
3answers
312 views

Highlighting text with StringReplacePart but also using Style, Subscript

For a Natural Language Processing analysis task it's desirable to highlight a text string programmatically according to XML tags that reference specific words or phrases. The XML tags specify the ...
11
votes
2answers
334 views

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

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

Formatting text through pattern matching

I am trying to format some text based on some patterns. ...
17
votes
2answers
960 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
201 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
266 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 ...
25
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
242 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 ...
22
votes
6answers
620 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
228 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 ...
9
votes
2answers
341 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
467 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 ...
18
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
306 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
837 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
234 views

Behavior of ImportString in Mathematica

I tried the following commands ...
7
votes
3answers
531 views

Creating word histograms from lists of strings

Consider the following: ...
6
votes
3answers
852 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 ...
13
votes
7answers
712 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
371 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
275 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
341 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 ...
17
votes
3answers
471 views

Unicode-aware string functions?

I've recently discovered that ToUpperCase is quite unreliable on non-ASCII input: ...
-2
votes
1answer
209 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 ...
23
votes
7answers
1k 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
592 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
707 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
305 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
235 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. ...