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 not deleted user 731

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

2 votes

StringCases functionality on a varying rows of data

One way using string patterns and StringCases like this: string = ImportString["<12> cfg <15.21> bhg v<(24)> e<65> True <12> cfg <15.21> bhg v<33> e<(77)> False <83> fff <67> …
C. E.'s user avatar
  • 71.2k
4 votes
Accepted

StringCases functionality

You say you manipulated the string before and that's why it's missing a brace at the end. It looks like you may have deformed a JSON string, in which case you did yourself a big disservice as such lis …
C. E.'s user avatar
  • 71.2k
2 votes

Swap first and last names in a list

Two ways I think will work for you, if not please provide some sample data: list = ImportString["Lastname, Firstname, Initial Lastname, Firstname, Initial Lastname, Firstname, Initial Lastna …
C. E.'s user avatar
  • 71.2k
20 votes
Accepted

Opposite of StringSplit

A combination of StringJoin and Riffle: res = StringSplit["a b c d e f g"," "]; StringJoin@Riffle[res," "]
C. E.'s user avatar
  • 71.2k
17 votes
Accepted

Get all pairs of same consecutive characters from string?

str = "AabHHioPjggtYuggbwq"; StringCases[str, x_ ~~ x_, IgnoreCase -> True] {"Aa", "HH", "gg", "gg"} Or in the generalized version of the question: str = "AaAbHHhhhioPjggtYuggGgGbwq"; StringCa …
C. E.'s user avatar
  • 71.2k
3 votes
Accepted

How to add the capital letters to Caesar´s Code?

I think you can work this out on your own so I wasn't intending to answer it, but I'll answer it since I'm not satisfied with the other answers so far. This is the simplest extension, in my mind, to y …
C. E.'s user avatar
  • 71.2k
7 votes
Accepted

Rule-based deletions from string list

You would need something like DeleteSubsequenceCases, but it doesn't exist. I would recommend this instead: SequenceReplace[lis, {d_?(StringMatchQ[NumberString]), ___, "X"} :> d] If X only appears …
C. E.'s user avatar
  • 71.2k
7 votes

Extract substrings with defined length from a string

Using Repeated: StringCases[ str, Repeated[_, {3}] ~~ " and " ~~ Repeated[_, {3}], Overlaps -> True ] {"his and tha", "hit and tha"} Note the use of Overlaps which is necessary for strings such …
C. E.'s user avatar
  • 71.2k
7 votes

How to capitalize the first letter of each word in a string

While I endorse Mr.Wizard's pattern matching solution and I've given Istvàn +1 I would also like to submit this function which is meant to not rely on string patterns and be as readable as possible: …
C. E.'s user avatar
  • 71.2k
1 vote

How to construct tuples with a given order?

It's a brute force approach: set = CharacterRange["A", "E"]; n = 4; tuples = Tuples[set, n]; Select[tuples, Order[#[[1]], #[[2]]] == 1 && And @@ Negative@Differences@Ordering@Rest[#] &] {"A", " …
C. E.'s user avatar
  • 71.2k
1 vote

How to remove duplicate characters from a string?

Just another way to do it without converting the string to a list. You have to define the character range. rest[x_ /; x == {}] := {} rest[x_] := Rest[x] str = "113233454766"; (str = StringReplacePa …
C. E.'s user avatar
  • 71.2k
2 votes
Accepted

Mathematica regex equvalent of \l

I believe this is what you want. StringCases["Abba", RegularExpression["(.).*(?=(?i:\\1))[a-z]"]] (?=(?i:\\1)) is a lookahead which says, "if the next character matches \1 in any case," but then it …
C. E.'s user avatar
  • 71.2k
3 votes

Splitting strings at lower case characters and numbers

elements = SortBy[ElementData[#, "Abbreviation"] & /@ ElementData[], Minus@*StringLength]; StringCases["Fe3O2", DigitCharacter .. | elements] {"Fe", "3", "O", "2"} (Thanks to Mr.Wizard for synt …
C. E.'s user avatar
  • 71.2k
2 votes

How do I pad numbers to the left so that all are the same length?

One way: If[StringLength@# == 1, "0" <> #, #] &@*ToString /@ {-6, 1, 3, 23} Another way: StringJoin@*(ToString /@ PadLeft[#, 2] &)@*Characters@*ToString /@ {-6, 1, 3, 23}
C. E.'s user avatar
  • 71.2k
6 votes

A too complicated lookup

Another option: AssociationThread[nm -> ln]["tat"] If you store AssociationThread[lm -> ln] in a symbol you can use it for many quick lookups without having to recreate the association every time. …
C. E.'s user avatar
  • 71.2k

15 30 50 per page