Tagged Questions

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

learn more… | top users | synonyms (2)

5
votes
5answers
328 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 + ...
4
votes
3answers
193 views

Reading binary strings from file as strings

I have a file that contains binary strings like 01011 00101 01011 I want to import the file to Mathematica as a list of strings, but ...
6
votes
3answers
419 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 ...
2
votes
3answers
158 views

Counting instances where the two identical characters are at the same positions in two strings

Let $s_a$ and $s_b$ be two strings over a $q$-ary alphabet. For each character $(c_1,...c_q)$ in the alphabet, I'd like to return a pair of values $(r,k)$ where $r$ represents the count for the ...
3
votes
3answers
112 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 ...
7
votes
3answers
163 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*) ...
5
votes
1answer
188 views

Sorting an Array with words in different languages

Array consists of words of different languages. I need to sort elements in reverse alphabetical order and make a list of elements, which consist of english letters. Example of array which consist of ...
0
votes
1answer
42 views

Replacing character in position

I'm trying to use Mathematica to make some work on binary data, and I'm missing something. Consider the string "111". I want to flip the last bit to become ...
0
votes
0answers
15 views

Evaluating a String that is a Variable [duplicate]

I have a Variable assigned a value, say ImportantDocuments=1 How do I make N["ImportantDocuments"] evaluate to be 1 instead of ImportantDocuments I found that ...
0
votes
2answers
148 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 ...
5
votes
1answer
80 views

Converting StringForm output to a string produces unexpected results

I want to compose a string that contains newlines, so I tried the following: ...
0
votes
1answer
90 views

How to convert the expression '{a->a0, b->b0}' to the expression 'a=a0; b=b0'? [duplicate]

How to convert the expression '{a->a0, b->b0}' to the expression 'a=a0; b=b0'? I think this is a common question and do not know if someone has asked it before. Any help or suggestion will be ...
0
votes
1answer
140 views

How to replace characters which have alternate meanings in strings. This code works, but creates errors

The Problem: I often paste strings into Mathca which have many what I call "extender characters" --which may extend the character set." We know these have to be dealt with so Mathca can deal with ...
6
votes
2answers
146 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 ...
1
vote
3answers
86 views

Options in a StringReplace rule

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

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

I have made this function: conv01 = Map["["<>StringJoin@@Riffle[#,","]<>"]"&,Map[ToString,#,{2}],{0,1}]& to convert: ...
1
vote
1answer
186 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). ...
6
votes
2answers
172 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
248 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
163 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. ...
3
votes
0answers
75 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? ...
6
votes
4answers
283 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. ...
1
vote
0answers
31 views

How can I convert a matrix into matlab form string? [duplicate]

How can I convert a matrix into matlab form? ...
3
votes
2answers
121 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 ...
2
votes
1answer
86 views

Make MyLogicalExpand

The function by Mathematica to expand a formulation with ANDS, ORS, NOT, XOR, and others, is LogicalExpand, let see an example: ...
3
votes
1answer
206 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: ...
12
votes
4answers
473 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/
2
votes
1answer
154 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: ...
4
votes
2answers
479 views
12
votes
5answers
518 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 ...
1
vote
1answer
82 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};` ...
9
votes
1answer
125 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? ...
5
votes
2answers
205 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 ...
3
votes
1answer
105 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
290 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 ...
4
votes
0answers
66 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: ...
7
votes
3answers
441 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
227 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 ...
4
votes
4answers
195 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
223 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: ...
3
votes
1answer
432 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
129 views

StringCases functionality

I have a list of strings in where each element of the list is in this form: ...
16
votes
1answer
302 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
109 views

StringCases functionality on a varying rows of data

There is a string in this form: ...
1
vote
1answer
153 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 ...
4
votes
3answers
291 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
176 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
88 views

How to make the StringExpression not occur in my case?

Why is there a StringExpression in the following code? ...