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

learn more… | top users | synonyms (2)

0
votes
2answers
56 views

Using StringReplace to make file names

Often I'm making many plots for different values of parameters. Each plot has a nice PlotLabel with superscripts, subscripts and some special characters. I would ...
1
vote
3answers
193 views

Swap first and last names in a list

Edited to fix an inconsistency in the given example data format. I'm trying to write a simple function to load in a csv list of names which is formatted as "Lastname Firstname Initial " and ...
1
vote
3answers
345 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 ...
1
vote
1answer
49 views

Are all of the numbers in my file legitimate hex numbers

I have about 10,000 hexadecimal numbers (32 digits each) in an excel file, in one column. I want to verify that all of them are indeed hexadecimal number and that no other characters are present. My ...
0
votes
2answers
73 views

Is there a manual way to generate a string of zeroes with a 2 at the end?

How do I get mathematica to display 33141015 zeroes and a 2 I've tried using 2*10^-33141016 but it just gives me scientific notation Is there a manual way to generate a string that looks like ...
10
votes
1answer
326 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 ...
0
votes
0answers
44 views

Is there a better way to search a string so that I don't get false positives? [migrated]

I've been using this equation to find primes of a specified range, in this example the range is 10 to 10000. Go ahead and try it out, your monitor will not catch fire. The problem I'm now having is ...
0
votes
0answers
58 views

Need help with formula for generating primes [migrated]

I've done this: N[Sum[(10^(n*2) + 1)/(10^(n^2*2)*(10^(n*2) - 1)), {n, 1, Floor[49^(1/2)]}], (49)*2] ...
3
votes
2answers
183 views

Regular expression too large problem

pattern = Names["*"]; StringMatchQ["Bold", pattern[[1 ;; -1 ;; 2]]] (* True *) StringMatchQ["Bold", pattern] Error Information: ...
2
votes
1answer
76 views

Optimizing alphametrics code

First of all, thank you all in this great community. I have been reading a lot of threads about Mathematica optimization learning things like using Compile ...
1
vote
1answer
53 views

Using the string Match with options! [duplicate]

Here is what I want to do: I have a list of strings for example s={"red carpet","red box","black carpet","black box"} I want to use something like ...
18
votes
1answer
506 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 ...
0
votes
1answer
75 views

How to fill a Marshal buffer with whitespace using NETLink

Further to Todd Gayley's answer on string handling in a DLL function, I have the following code: ...
4
votes
3answers
173 views

How can I improve NumberString?

I would like to test strings to see if they represent numbers. This should include number representations with precision marks and scientific notation. NumberString ...
3
votes
1answer
34 views

Is the use of StringTemplate with a styled string documented behavior?

I was pleasantly surprised to find out that StringTemplate appears to work with styled (formatted) strings, with the style of the slots applied to the inserted ...
2
votes
0answers
84 views

How to efficiently find parts of a string with beginning and ending specified?

I'm trying to find specific URL addresses from a html document. The addresses can be found between the strings "href=\"" and "\" class=\"listing". The problem is not including strings like this: ...
17
votes
8answers
2k views

How to express an integer number in English words?

How do I convert a number to a readable string? I would like to implement a function, inWords[], inWords[n_]:= ? which ...
8
votes
2answers
104 views

Convert recursive RegularExpression to StringExpression?

Consider the following expression for matching balanced brackets: ...
4
votes
1answer
129 views

Extra spaces when exporting strings into pdf (bug, linux)

Rationale: Imagine you would like to create a publication quality figure in Mathematica, from under Linux. Naturally, it will contain text/labels. Problem: Here is a simple string ...
1
vote
2answers
56 views

Why doesn't ToString work in ReplaceAll? [duplicate]

I'm trying to use ReplaceAll in a subscript. However, it doesn't seem to work as expected if I want to use the output the subscript in a ...
3
votes
1answer
59 views

Strings with exclamation marks in Mathematica [duplicate]

Given this input FullForm[ToString[TraditionalForm[x]]] Mathematica outputs "\!\(TraditionalForm\`x\)" It seems like ...
6
votes
1answer
105 views

Limit characters/digits entered into InputField

When using InputField, whether setting the input type as a Number or String, is there a way ...
6
votes
3answers
259 views

Finding all sublists or substrings of a given list/string

Given a list or string, how do I get a list of all (contiguous) sublists/substrings? The order is not important. Example for lists: ...
0
votes
2answers
154 views

Exctrating data information from a file.txt

I really did previous long search in the site and I couldn't find any answer that might help me. So I am asking it. I have the following data set, ...
5
votes
3answers
401 views

Camel hump string split

Given System names of 2 or more characters: systemNames = Names["System`*"] // Select[StringLength[#] > 1 &] ; Is ...
4
votes
1answer
61 views

How to convert expression with Subscript to string

I've tried ToString[], but it doesn't work properly with subscripts: How to convert expr with subscript to string with exactly the same FullForm that "expr" has?
4
votes
1answer
89 views

Parsing string with nested information

I am trying to parse a string, but I have no idea how to solve the following problem ...
0
votes
2answers
78 views

Decimal-to-ASCII conversion

I have to write a program that converts a number (decimal notation) to an ASCII string. For example, x = 26728 (or 0x6868) and the string is "hh". I wrote this, but it seems that it is not the ...
1
vote
0answers
70 views

Geodesy without units?

Suppose I'm interested in the latitude of Los Angeles and I do the following: ...
1
vote
0answers
43 views
0
votes
1answer
65 views

Data file organized in strings

I am working in a data set : The original question, They are strings of thousands stars,and each one contains a lot of parameters, and the following item is called identifies, they are the names ...
7
votes
1answer
128 views

LetterCharacter for Cyrillic symbols

Why does the code StringMatchQ["ы", LetterCharacter] return False? Probably because: ...
10
votes
2answers
145 views

Unexpected result from StringReplace

The following works as expected. StringReplace["xxxyxz", "x" ~~ _ -> "ww"] "wwwwww" And so does this. ...
23
votes
1answer
274 views

StringCases is Confused with Patterns in Version 10.0.1

I observed the following with StringCases when trying to use rules/patterns. Here is a screenshot of the behavior: Not only is the pattern highlighted in red, ...
6
votes
4answers
174 views

Generate list of strings from a list of assigned variables

How do I generate a list of strings from a list of assigned variables? Eg. Convert ...
11
votes
3answers
263 views

ToExpression fails with long nested string expressions

Consider the following conversion from String to Mathematica Expression: ...
0
votes
0answers
29 views

Error when converting a string involving superscript after closing square bracket using ToExpression

I would like to store a piece of code in the form of a string, make some string transformation to it and get the new code evaluated using ToExpression. Everything works just fine but one: if there is ...
16
votes
2answers
549 views

Why is TextString[-0.5] a positive number?

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 result of my 3-weeks ...
3
votes
2answers
138 views

how to extract the string using regular expressions

I have the list : a1 = {"struct name1 {","struct name2{","struct name3{","struct name4{", "struct name5{","struct lastStruct{"} I tried to extract the ...
1
vote
1answer
134 views

how to make a recursive function to analyse this file

I am stuck at this problem beginning We assume we have keyword k, and the structure in the file: file.txt ...
3
votes
1answer
45 views
2
votes
1answer
54 views

How can I automatically name files being exported based on input parameters

I have Mathematica notebook that performs some operation say a=2 b=3 c=5 d=4 how do I set the output file after evaluation to be named using the values ...
1
vote
1answer
57 views

Find item in a big list that contains a specific string [closed]

I have a huge list with 17,576 (=26^3) items in it. All items consist of a long string of text about 1,200 or so characters long. These strings were all generated ...
1
vote
1answer
34 views

Creat a global variable from an argument and being able to use it as a numeric input

I want something like this: myfun[j_]:=Block[ {ans}, ans = Range[j]; "phi"<>ToString[j] = Total[ans]; ]; The procedure is just an illustrative ...
0
votes
1answer
54 views

TraditionalForm for PlotLabel with a parameter

This is a simple variation/spin off of this question, but I am having trouble. In the second example in the original question, I'm trying to get the $a=$ in the ...
31
votes
1answer
550 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: ...
6
votes
4answers
630 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 ...
3
votes
3answers
210 views

String pattern defined by number of characters

I want to extract non-overlapping substrings from strings with only four possible characters a,b,c,d. These strings will always have equally many "a" and "d" characters. The substrings x I want satisy ...