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

learn more… | top users | synonyms (4)

3
votes
1answer
52 views

Prevent expression from evaluation in function when using `ToString `

I defined function fhold Clear[fhold] SetAttributes[fhold, HoldAll] fhold[para_List] := ToString[para]; What I want is that ...
4
votes
1answer
121 views

Permute list of strings

Say I have a list of strings like slist={"apple","123","Car"} What I want is a list of all permutations of slist. The result ...
2
votes
1answer
54 views

Using strings in defining rules

I am very new using Mathematica and I would like to define a rule of replacement which operates as below, keeping freedom for what concern the pre-factors that can appear in the equation: $$e^{\pm ix} ...
5
votes
5answers
527 views

Joining some strings in a list of strings

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

How to transform data in character form into a sensible form?

I have a data output from a device in a form of a string. I need to transform it into such a form that I can work with it, such as plot columns with respect to one another and such. After a apply ...
2
votes
1answer
155 views

Replace punctuation marks in strings with spaces

I have a list of strings. Some of them contain commas, single quotes, etc. Is there a quick way to replace those characters by blanks? My list looks something like this: ...
3
votes
2answers
80 views

How remove specified substring and everything after it to the end of a string?

If I have, say, the string, txt = "now is the time for all (good) men" then I want to remove the substring beginning with "for" and ending at the end of the ...
5
votes
0answers
53 views

SimilarityRules for SequenceAlignment of two lists

I am trying to use the SimilarityRules option of SequenceAlignment to customize its output. This works perfectly for strings, ...
0
votes
1answer
33 views

Regular expression help for arecord command output

How do I get the card number and device number alone from this string by using a regular expression to parse it? Here's the string ...
3
votes
0answers
49 views

Why was StringRepeat designed so that StringRepeat[s, 0] throws an error?

I'm wondering about the rationale behind the design decision that leads to the following expression throwing an error: ...
8
votes
2answers
283 views

How can I use words/letters as pixels in an image?

I'd like to take the text of a novel or whatever and arrange it in a way that forms an image. Essentially recreating these works from Postertext. . I'm mostly looking for ideas regarding a ...
3
votes
1answer
66 views

Whitespace is lost during MathML -> XMLElement conversion

ImportString["<mtext> </mtext>", {"MathML", "XMLElement"} ] XMLElement["mtext",{},{}] while I'd expect: ...
0
votes
1answer
58 views

How to implement the for loop to replace text strings or texts?

I wonder define a bunch variables named like $X_1$, $X_2$, $...$, $X_n$. Is there some smart way to declare them instead of by pure typing. One trick I can image is to use the for loop,...
0
votes
2answers
87 views

How to make an Histogram where the data are strings? [duplicate]

Histogram[{3, 3, 2, 2, 2, 2, 2, 1, 1}] works great to give you an histogram in which mathematica counts the occurence of each number and makes the plot. Is there a ...
15
votes
1answer
228 views

Mma 10.2 `Alphabet` and `LanguageData` give different and both erroneous list of letters

Bug introduced in 10.2 and fixed in 10.3 The new function Alphabet introduced in Mathematica 10.2 gives the wrong list of letters for the Spanish language in my ...
2
votes
2answers
203 views

What's wrong with my palindrome finding function?

I'm trying to find the palindromes in the dictionary, but my output isn't giving me all of them. I have this so far ...
0
votes
0answers
85 views

Home Loan Calculator with Variable Interest

I have to make a calculator for a home loan and currently the interest rate is fixed (constant for the entire period of the loan) How can I make the sliders on manipulate so that after each period of ...
4
votes
5answers
170 views

Converting set of characters into numbers using list of replacement rules

I am trying to convert a text, as an example "aaaa" into a set of numbers as defined in a list of replacement rules, for example letterstonum . letterstonum takes in letters a to z and returns the ...
2
votes
0answers
34 views

How can I construct a string pattern from a list of patterns? [duplicate]

Is it possible to construct a string pattern from a list of strings? ...
2
votes
1answer
57 views

Braces in pattern with Cases function

Here's my problem: I've got a JSON-formatted response and want to match some variables over the response. I'm doing it using Cases: ...
4
votes
2answers
114 views

Printing every other line from input text

I am trying to do some text manipulation in Mathematica. After importing a text file (in.txt) as a string, how would you then output every other line? In the ...
14
votes
4answers
961 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. ...
2
votes
1answer
66 views

Having trouble modifying entry in a list

Hi, I am trying to create a small repository by entering three things as a list of string, namely the asp, sequence and description. The trouble that I am facing is that while I am manually ...
7
votes
1answer
144 views

How to get string representation of boxes in v10.2?

In Mathematica versions up to 10.1 we could get string representation of given boxes by passing them to ToString with InputForm: ...
0
votes
1answer
51 views

Avoiding misconversion of data with ToExpression function [closed]

I've got a list of data with the following structure which can be easily converted To expresion by some manipulation such as ...
13
votes
6answers
333 views

How can I mix the behaviors of StringReplace and ReplaceAll in a single rule?

I'm trying to take a list of the form { {"65 + 3 months", 75}, {"65 + 4 months", 75.1} }, and transform the string part to a number such as 65.25 or 65.333, ...
1
vote
3answers
100 views

Keep leading/trailing zeroes (like Defer except with numbers) in a given number

I'm trying to write a function that counts the number of significant figures a given number has so I can ensure my calculations are rounded correctly; however, I am having a lot of trouble preventing ...
5
votes
4answers
238 views

Finding relevant parts in XML document

My question is about a XML document and finding parts of strings. test = Import["C:\\Users\\filename.xml", "XMLObject"] This gives the following output: ...
5
votes
3answers
498 views

Finding all of the words containing certain letters

Is there a fast method to find all of the words containing the letters: {a, e, i, o, u, y}? I created an algorithm, but it takes more than 11 seconds to find all of ...
4
votes
2answers
95 views

Using parenthesized Regex backreferences in StringReplace

(I am sorry for my poor English,I'll try to use a simple sentence to convey me.) I can use StringCases to get the target to change like this ...
2
votes
1answer
65 views

Recurrence relation for multivariate polynomials

I am trying to define a function which recursively computes a polynomial associated to every binary string: ComputePoly[s_]:=(** Recurse on the string s**) For ...
1
vote
1answer
47 views

How to reference StringExpression named parts from a package without full Context path?

I have a long StringExpression in a package returned by a function. There are some named parts in the expression that I would like to reference when I use the ...
1
vote
2answers
54 views

Detect Mathematica operators eg. \[CircleTimes] in strings

I'm trying to detect all Mathematica operators/symbols (eg. [CircleTimes], [Colon], etc.) in strings so I can replace them with something else, how can I achieve that?
1
vote
1answer
38 views

FromDigits gives “not a list of digits” error for integer string in StringExpression rule of StringCases

I have large StringExpression that is used in StringCases. Some of the parts being pulled out are integer strings. These pull ...
1
vote
2answers
114 views

ToExpression and Fortran notation

ToExpression["9.0E-03"] interprets the string as 9*e - 3 instead of what I am expecting: ...
21
votes
1answer
548 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 ...
7
votes
2answers
118 views

Strange Error on Fresh Kernel (10.2)

Bug introduced in 10.1 I wrote a helper function to format real numbers in a certain format for writing .dbf files here. It relies on a new function to 10.1 - ...
5
votes
1answer
164 views

Escaping multiline strings in Mathematica

I want to assign long multi-line strings in Mathematica. Is there a way of delineating a block without having to escape each instance of '"' with '\"' and each line ending with '\'? i.e. In other ...
2
votes
3answers
182 views

Problem displaying uppercase “I” in a string [duplicate]

It seems that Mathematica reserves the capital i, I, for the imaginary unit. I have the following expression: expr = a.b + II ...
13
votes
4answers
395 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 ...
6
votes
4answers
277 views

Shorter shorthand for StringJoin[]?

As a minimal working example: myString="some words"; myString=myString<>"more words"; Is there a shorter way to tell Mathematica that I want to "tack on" ...
8
votes
1answer
167 views

Simple string pattern crashes kernel

Bug introduced in 6.0 or earlier and fixed in 10.1.0 The following code crashes my Mathematica kernel (v9, MacOS): ...
25
votes
1answer
317 views

StringCases is Confused with Patterns in Version 10.0.1

Bug introduced in 10.0.1 and fixed in 10.0.2 I observed the following with StringCases when trying to use rules/patterns. Here is a screenshot of the behavior: ...
6
votes
7answers
355 views

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

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

Using Probability for n-gram string queries

I want to use Probability to ask questions on strings like "what's the probability of the occurrence of the trigram 'the' conditioned on the occurence of the digram 'th'?" This doesn't work. I ...
10
votes
1answer
221 views

How to change the font color of a variable in whole input cell

I want to track the occurrence of a particular variable in a code. So the idea is to change its color. Usually I do it in a crude way - convert the code into text and then use ...
21
votes
2answers
597 views

Why is TextString[-0.5] a positive number?

Bug introduced in 10.0 and fixed in 10.0.2 I want to format numbers in decimal notation and chose TextString for this task. But today, when looking at the final ...
1
vote
2answers
50 views

How to define a function `deriv[f[x]]` such that its output is an unevaluated expression `fx=D[f[x],x]`?

I want to define a function deriv[f_[x_]] such that when I run deriv[f[x]], the output is an unevaluated expression ...
35
votes
2answers
834 views

String-manipulation bugs in v10.1

Fixed as of 2015-04-06 via paclet update. The new version 10.1 has introduced some strange (possibly buggy) behaviour compared to v10.0: ...
2
votes
1answer
57 views

How to extract part of association?

Considering an association: asc = <|"a"->1, "b"->2, "c"-><|"e"->3, "c"->4|>, "d"->5, "e"->6, "f"-><|"g"->7|>|> How ...