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

learn more… | top users | synonyms (2)

2
votes
1answer
85 views

Make MyLogicalExpand

The function by Mathematica to expand a formulation with ANDS, ORS, NOT, XOR, and others, is LogicalExpand, let see an example: ...
2
votes
1answer
220 views

Change values in string under condition

how to change the width and height in the HTML code into some other values decided by ratio and a fixed width? The background is that you can adjust a image in ...
12
votes
5answers
483 views

How to remove duplicate characters from a string?

How do you remove duplicate characters in a string without converting the string to a list. I want to delete all duplicate characters in a string (i.e. get the unsorted union of characters). For ...
2
votes
1answer
142 views

Elegant transformation of various rules to strings, {f[z_] -> y} becomes “f = @(z) y”

Assume that I have some function for transformation mathematica expressions to strings. For simplicity, just assume it is an identity: ...
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 ...
9
votes
4answers
382 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 ...
1
vote
1answer
81 views

Insert glyphs into a string using functional code

I asked this question few days ago: Replace For-loop with functional code Suppose I use strings instead of lists; for example a = ToString /@ {123123, 112233};` ...
5
votes
2answers
193 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 ...
9
votes
1answer
119 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? ...
3
votes
1answer
84 views

Use of StringExpression as argument

Is it possible to use a StringExpression as a pattern for an argument? I.E. something like foo[chars__~~ WordCharacter.. ~~ num:NumberString] := {chars, num}; At ...
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 ...
7
votes
3answers
386 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. ...
4
votes
0answers
64 views

Error with String patterns producing Removed[“$$Failure”]

While working on How to capitalize the first letter of each word in a string and trying to understand why certain characters were not considered letters I tried this: ...
4
votes
4answers
185 views

How to construct tuples with a given order?

How do I create a list of tuples with an ordering imposed on them, where each element is from a generating set? Specifically, I'm trying to create a listing of tuples $(x_1, x_2, ..., x_n)$ such that ...
5
votes
2answers
199 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
3answers
279 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 ...
2
votes
1answer
302 views

Convert String to List of Numbers

I want to create a function that when a string is entered it will turn it into a list of numbers, these numbers are the numerical form of the characters in the string. e.g. a=1, b=2, c=3, d=4 and ...
-3
votes
2answers
115 views

StringCases functionality

I have a list of strings in where each element of the list is in this form: ...
11
votes
2answers
266 views

Transform fancy usage messages in 1D string

When we look at the usage messages of built-in functions nowadays (not in the good old times, when they were a simple descriptions) we see that although they look pretty in the front end, it is really ...
15
votes
1answer
261 views

How to strip all formatting from a string and convert it to plain text?

The documentation on String states: But if I try to perform some manipulations on this string, for example, take 2 words from the left, I get some shards of ...
2
votes
2answers
106 views
0
votes
3answers
341 views

How to export a header before the data in the result file?

I would like to export a phrase to my result data as a heading. I'm exporting the data correctly with Export["file.dat", table]. But I'm doing several ...
19
votes
7answers
962 views

Elegant and fast way to join all string sequences

I want to do what title says: {"a","b",1,2,3,4,"a",2,2,2,"edg","?"} => {"ab",1,2,3,4,"a",2,2,2,"edg?"} in the most elegant way. For example one replacement rule for ...
1
vote
1answer
135 views

Style markers in strings

I'm dealing with strings in Mathematica and I would love to handle their stylling in the most cenvenient way. Without loss of generality, let's assume I want to make some parts of string ...
1
vote
2answers
93 views

String pattern with symbols [closed]

I have got a huge list with elements like this: {":"ofa-legacy-conference",", ":"obama-2012",", ":"ofa-states","} The first element is ...
4
votes
3answers
203 views

Using subscript in a string

I am trying to create a string of the form $0 < d_1 < d_2 < \ldots < d_n$ For a given n. My closest attempt so far is ...
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 ...
1
vote
1answer
82 views

How to make the StringExpression not occur in my case?

Why is there a StringExpression in the following code? ...
2
votes
1answer
483 views

How to import a Microsoft Word document into Mathematica?

I have a Microsoft Word document in DOCX format. I need to import it into Mathematica as a String preserving all formatting (font, size, bold/italic style, colors, ...
3
votes
2answers
223 views

StringReplace except some pattern

StringReplace and search out of one pattern ...
1
vote
3answers
277 views

Replace with position and order number

question conversion1 : Convert "[AA]AB[AA]BB[AA]B[AA]CCC" to "[A1A2]A3B1[A4A5]B2B3[A6A7]B4[A8A9]CCC" conversion2 : Convert ...
17
votes
3answers
336 views

Unexpected result {“.a”, “co”, “.m”} from Sort[{“.m”, “.a”, “co”}]

I came across the following situation: Evaluating Sort[{".m", ".a", "co"}] Results in {".a", "co", ".m"} I wondering: ...
9
votes
3answers
235 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 ...
1
vote
0answers
98 views

Split one string about a fixed width with `SyntaxQ=True`

How to split one string about a fixed width, the string may come from the input or output cell of Notebook. sample string ...
3
votes
1answer
140 views

Importing strings in Mathematica

This is my first post so apologies if any obvious mistakes. I'm trying to work on a data containing names (in quotes) in Mathematica. The data is already saved on my system under ...
6
votes
1answer
224 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
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". ...
1
vote
1answer
127 views

Searching a string that may contain Null

I have an array of triplets that can be approximated by the following code: ...
2
votes
1answer
182 views

Showing special characters in text containing unicode

How does one conveniently convert a string like: "Ya no me burlar\:00e9 de la diabetes de Nick Jonas. Me lo guardar\:00e9 para cuando le corten la pierna. S\:00ed es que a\:00fan alguien lo recuerda, ...
3
votes
5answers
316 views

How to write a function to remove comments from a .m source file preserving formatting such as line wrapping reasonably?

How to write a function to remove comments from a .m source file preserving formatting such as line wrapping reasonably? This means if I have ...
5
votes
6answers
207 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): ...
2
votes
1answer
155 views

Explicit asterisk or @ sign in string patterns

What string pattern will match an explicit asterisk (*) or at-sign (@)? The obvious example, StringMatchQ["*", "\*"], returns ...
4
votes
5answers
239 views

A simple StringCases problem

Given this text: text1 = " A Vitamin D Deficiency (ICD-9-CM 268.9) (ICD-9-CM 268.9) 09/11/2015 01 "; Yes, the ICD code values are duplicates- possibly but ...
27
votes
0answers
420 views

Why is StringExpression faster than RegularExpression?

Edit: as noted by Albert Retey the performance difference is only seen when sub expression extraction is performed. If this test is used below the timings are similar: ...
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
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 ...
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. ...
3
votes
1answer
237 views

String replacement to make the TeXForm output beautiful

This question is inspired by this question: How to convert the symbol $d$ in Integrate into $\mathrm{d}$?. Although it’s not a big problem, the TeXForm can be ...