Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 3066

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

1 vote
Accepted

Wrapping long strings at word breaks

I am not sure I correctly understand what you are asking, but I tried the following: fox = "The quick brown fox jumped over the lazy dog. "; longFox[n_] := StringJoin[Table[fox, {n}]] long = longFox[1 …
m_goldberg's user avatar
  • 108k
2 votes

How to convert expression to String, but keep it looking similar to input form?

This is pure string hackery and I don't know how robust it is, but it works on your test case and one other that I tried. helper[l_, d_] := l <> StringJoin @@ ConstantArray["'", ToExpression[d]] SetA …
m_goldberg's user avatar
  • 108k
2 votes

Using StringExpression in file name

This seems to be reasonably robust. You can even use wildcard * in the name string, but in that case you will open the file which is 1st match in the list returned by FileNames. openNBorCDF[name_Strin …
m_goldberg's user avatar
  • 108k
3 votes

Removing commented lines of text in a string

This answer only discusses the implied question of why the OP's code fails. I think this should be made clear because it puzzled me until Mr.Wizard and rm -rf enlightened me. I would like keep others …
m_goldberg's user avatar
  • 108k
1 vote
Accepted

Usage of StringTemplate

The documentation example is clearly wrong. Probably was written without proper testing. A second argument giving a spacer element must be added to Row. The quotes delimiting the spacer string must be …
m_goldberg's user avatar
  • 108k
9 votes
Accepted

Replacing doubled letter with that letter plus a code

StringReplace["hello, this is silly", x_ ~~ x_ -> x ~~ "X"] "helXo, this is silXy"
m_goldberg's user avatar
  • 108k
1 vote

How do I replace all strings in a list with one of any substrings?

You could use StringDelete data = {"abc", "abd", "abx", "abf", "abe", "abg", "abh", "abi", "acb", "acd"}; StringDelete[data, {_ ~~ "bd", _ ~~ "bg"}] // DeleteCases[""] {"abc", "abx", "abf", "abe …
m_goldberg's user avatar
  • 108k
6 votes

Using Position to get position of string of a list of strings

Position has some unusual defaults. As ref/Position says The default level specification for Position is {0,Infinity}, with Heads->True. So it is a little tricky to use StringContainsQ directly …
m_goldberg's user avatar
  • 108k
6 votes
Accepted

Converting StringForm output to a string produces unexpected results

I ran into this problem in 2009. I submitted it to WRI technical support. This is the reply I received. After going through your notebook, I believe that what you observed is the expected behavi …
m_goldberg's user avatar
  • 108k
3 votes

Rule transformation between letter and number

Here is a formulation using regular expression groups and POSIX character classes. transformRules = (# -> First @ StringCases[ToString[#], RegularExpression["([[:alpha:]]+)( …
m_goldberg's user avatar
  • 108k
8 votes
Accepted

StringMatchQ fails using Alternatives with complex pattern

The problem arises from naming the inner sub-patterns in your two pattern definitions with the same identifier. When you combine the patterns with Alternatives, you then have a pattern with two sub-pa …
m_goldberg's user avatar
  • 108k
4 votes

Finding strings in Web Code

You can use Shortest if the sub-strings of the form <td, class=test, >...</td> don't contain nested sub-strings of the form <td, class=test, > or </td>. If they do, follow this link. v = "...<td, cl …
m_goldberg's user avatar
  • 108k
5 votes

Problem with WordBoundary in string patterns

There is a reason to use WordBoundary, but your example sentence doesn't bring it out. Consider mystring = "I am a demanding fan of Superman, Spiderman and Batman."; StringCases[mystring, LetterChar …
m_goldberg's user avatar
  • 108k
6 votes

Built-in way to convert Integer to Ordinal String

A brute force but very simple approach (no undocumented functions needed) that I think will work with any version of Mathematica. ordinalRule[n_Integer /; Mod[n, 100] == 11] := generalRule[n] ordinal …
m_goldberg's user avatar
  • 108k
3 votes
Accepted

Regular expression help for arecord command output

You don't need regular expressions. text = "~ $ arecord -l **** List of CAPTURE Hardware Devices **** card 0: usb device [usb device], device 0: Audio [Audio Input] Subdevices: 0/1 Subdevice #0 …
m_goldberg's user avatar
  • 108k

15 30 50 per page