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

learn more… | top users | synonyms (2)

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 ...
8
votes
2answers
301 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 ...
8
votes
1answer
100 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
233 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 ...
7
votes
3answers
387 views

How to capitalize the first letter of each word in a string

The following examples only work for the first character of the whole string, but not of words. ...
7
votes
3answers
270 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 ...
7
votes
5answers
240 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 ...
7
votes
3answers
492 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? ...
7
votes
3answers
152 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
2k 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
171 views
7
votes
3answers
212 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
2answers
271 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
0answers
186 views
+50

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 ...
6
votes
4answers
271 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
2answers
454 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
737 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 ...
6
votes
2answers
151 views

How to Clear variables represented as a list of strings?

Say I have a string list called fullpara fullpara={"width", "long", "line", "distance"} And there are corresponding variables ...
6
votes
3answers
225 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: ...
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) ...
6
votes
3answers
248 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: ...
6
votes
2answers
123 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 ...
6
votes
1answer
251 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): ...
6
votes
1answer
190 views

Match sequence of zero or more characters except a given character

This looks like it should be simple: I want to match an "i" followed by an "o" with an arbitrary (possibly zero-length) sequence of characters in between, unless that sequence also contains an "i". ...
6
votes
3answers
291 views

neighbor swapping distance between two strings

Updated Problem Description I have a collection of strings $S$ that only contain two (or $m$ in general) kinds of elements: in this case C and D. For all $s\in S$, the length is the same, the number ...
6
votes
1answer
221 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. ...
6
votes
1answer
226 views

String pattern search and replacement — it works, but produces error messages only the first time it is called

I defined a function in Mathematica to process a pre-generated string. More specifically, I'd like to process some parts of C codes generated from MMA. Basically what my function does is to expand the ...
6
votes
2answers
259 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 ...
6
votes
1answer
110 views

How does `LongestCommonSubsequence` work?

When I recently came across this posting about LongestCommonSubsequence I was curious about how the function worked. ...
5
votes
3answers
284 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 ...
5
votes
6answers
211 views

Selective thinning of string elements in nested lists

I have a nested list similar to this example list (but much bigger and more messy): ...
5
votes
3answers
491 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 ...
5
votes
3answers
266 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 ...
5
votes
5answers
439 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 ...
5
votes
3answers
463 views

Creating word histograms from lists of strings

Consider the following: ...
5
votes
4answers
271 views

Is there a more Mathematica-y way to label these plots?

I am studying an infinite square well in the context of quantum mechanics. ...
5
votes
5answers
323 views

Isolating characters in a string

I'm struggling to find the right function in mathematica to isolate specific characters in a string. I have got a formula as string (I imported it from an excelfile) like this: y = 0.97*x1 + ...
5
votes
6answers
273 views

Convert array from {{…}} to “[[…]]”

I have made this function: conv01 = Map["["<>StringJoin@@Riffle[#,","]<>"]"&,Map[ToString,#,{2}],{0,1}]& to convert: ...
5
votes
2answers
253 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: ...
5
votes
2answers
164 views

Extract substring by repeated StringPattern

This code failed, but may exemplify my intention. StringCases["aA1bbbbbbbbbbaA2baA3b...aA4b",Repeated[Shortest["a"~~xx__~~"b"],{2,100}]] I want to get the ...
5
votes
5answers
303 views

Joining some strings in a list of strings

So, say I have a list of strings, representing lines in a file, like so: ...
5
votes
3answers
224 views

String templating

I am pretty new to string processing in Mathematica. But I'm having some problems in doing simple string template filling to my mind elegantly. For example when doing export for my answer here, one of ...
5
votes
2answers
203 views

Removing commented lines of text in a string

Suppose that I have a string str. str contains headings -- which are written in commented lines -- and data. For example: ...
5
votes
2answers
137 views

Using StringCases and treating certain phrases as single words

My question is about StringCases. When I use this function, each word is separated by a ,. But I want some noun phrases like ...
5
votes
2answers
194 views

How to get complement of a pattern

I have a list. I want to get all the elements in that list which do not match a given pattern. That is, I want the strings which do not match any of the following patterns: First and last characters ...
5
votes
3answers
249 views

How can I find English words among the names of the characters in the Mathematica character set?

I want to find some single meaningful words in the "ASCII/Unicode" form characters. For example, I want to get alpha from ...
5
votes
2answers
156 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 ...
5
votes
3answers
166 views

DateList's aggressive interpretation of TimeML duration codes

DateList "aggressively" interprets strings, such as "p72h": DateList["p72h"] gives ...
5
votes
3answers
281 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 ...
5
votes
2answers
610 views

How to convert a string of number into real numbers without precision loss

I searched and did not find similar answers which can resolve the 'no precision loss' issue. A sample string is: ...