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

learn more… | top users | synonyms (2)

1
vote
3answers
76 views

Options in a StringReplace rule

case1 Options[f] = {"t" -> "0"}; f[___, OptionsPattern[]] := StringReplace["content", "t" :> OptionValue["t"]] f[] (* con0en0 *) case2 ...
5
votes
2answers
322 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: ...
0
votes
1answer
59 views

expression in an string

I want to create several directories "dir_i" in a mother directory "home". and put an specific file in each directory ...
5
votes
6answers
250 views

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

I have made this function: conv01 = Map["["<>StringJoin@@Riffle[#,","]<>"]"&,Map[ToString,#,{2}],{0,1}]& to convert: ...
1
vote
1answer
137 views

How to represent very long integers with at-most-8-digit(base-10) short integers with * and +

I need an algorithm in Mathematica, which can represent any very long integer, prime or not, into the the product operation "*" and sum "+" forms by short integers (not more than 8 decimal digits). ...
5
votes
2answers
128 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 ...
7
votes
5answers
234 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 ...
3
votes
2answers
121 views

String pattern matching & replacement

I would like to find all occurrences of a full stop "." followed by a capital letter in a string and have these replaced with a "; ". How do I do this in Mathematica? e.g. ...
5
votes
4answers
262 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. ...
3
votes
0answers
73 views

Copy string with markup so it looks good on input

How can I copy a string with a bunch of *Box expressions without it blowing up into the raw expression? ...
1
vote
0answers
29 views
3
votes
2answers
110 views

Mathematica regex equvalent of \l

In normal RegEx \l will make the character to the right lowercase. However, it seems like the RegEx in Mathematica does not have this functionality. For example ...
0
votes
0answers
29 views

Sorting String Date in Asceding Order [duplicate]

How do I order string dates (month/year format) in ascending order, e.g., from 11/2011 to 07/2012: 02/2012 04/2012 07/2011 08/2013 08/2011
12
votes
4answers
462 views

How do you get a list of filenames from a URL?

How would I get a list of filenames available at a URL? For example, list the files at: http://www1.ncdc.noaa.gov/pub/data/cmb/drought/weekly-palmers/2005/
3
votes
1answer
160 views

Extract date from a not well-formed string

Is there a way to robustly extract date and time from a text? Say for example: ...The event will be held on 17/10/2013 at 3:30 PM in the room 121 and everyone is welcome... should return: ...
10
votes
9answers
2k views

How do I extract a number from a string?

I want to extract the number from an alphanumeric string. This is what I tried: StringTake["thiru3", {6, 6}] The result I got is ...
2
votes
1answer
82 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
203 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
466 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
110 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
1k 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
352 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
79 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
185 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
118 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
70 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
220 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
352 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
58 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: ...
3
votes
4answers
171 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
175 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
258 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
213 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
111 views

StringCases functionality

I have a list of strings in where each element of the list is in this form: ...
11
votes
2answers
263 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
225 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
98 views
0
votes
3answers
288 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 ...
18
votes
7answers
913 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
120 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
89 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 ...
3
votes
3answers
161 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
152 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
73 views

How to make the StringExpression not occur in my case?

Why is there a StringExpression in the following code? ...
2
votes
1answer
395 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
202 views

StringReplace except some pattern

StringReplace and search out of one pattern ...
1
vote
3answers
251 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 ...
13
votes
2answers
351 views

How to embed an image into a string?

The documentation for String contains the following statements: Strings can contain any sequence of ordinary and special characters: … Strings preserve ...
6
votes
0answers
115 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 ...