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 84894

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

2 votes
Accepted

Reducing a list of strings to known signature strings

There might be some edge cases to consider, but you might approach it as follows. Create a replacement rule for each element of lis1 (and keep a list of such rules): replaceRules = (# ~~ ___ -> #) & / …
lericr's user avatar
  • 34k
7 votes
Accepted

Deletion of list elements by rule

Select[lis,StringContainsQ[","]@*Last]
lericr's user avatar
  • 34k
2 votes

Finding the letters in a string of characters

You introduce some confusion by setting Mystring to be a list Mystring = {"123456789"} Since List is such an important structure in Mathematica, many functions are designed to work naturally with Lis …
lericr's user avatar
  • 34k
1 vote

Alliteration on text

If your sample text is assigned to the symbol text, then you could do this: Select[Partition[TextWords[text], 2, 1], Apply[SameQ, ToLowerCase[StringPart[#, 1]]] &] Of course, this is a simplistic int …
lericr's user avatar
  • 34k
8 votes

Application for StringDelete

StringTrim[#, StartOfString ~~ DigitCharacter ... ~~ WhitespaceCharacter ...] & /@ lis or StringTrim[#, RegularExpression["^\\d*\\s*"]] & /@ lis
lericr's user avatar
  • 34k
6 votes
Accepted

How can we replace strings according to requirements?

I'd try something along these lines StringReplace[ text, RegularExpression["(?m)^whitenode(.*{a};$)"] -> "yellownode$1"] This solution relies on some assumptions. It doesn't account for extra wh …
lericr's user avatar
  • 34k
6 votes

String containing characters in the same order as other string

This one passes all of the tests I've seen so far, but I'm still not actually sure it will work for what you want to use it for. SameOrderQ[full_, abbr_] := StringContainsQ[ StringJoin[DeleteCas …
lericr's user avatar
  • 34k
1 vote
Accepted

Exact rules applied by StringReplace when two substrings are to be replaced?

Here's how I interpret the documentation: 1-1: "a", no match 1-2: "aa", no match 1-3: "aab", no match 1-4: "aabb", match rule "aabb"->"aab" 5-5: "a", no match 5-6: "aa", no match 5-7: "aaa", no match …
lericr's user avatar
  • 34k
0 votes
Accepted

How to convert strings to the same pattern

This is a more general implementation, and it happens to be a bit faster, although I'm not sure if that's what you meant by "efficient". It might require some explanation (see below). mergeAffixes[aff …
lericr's user avatar
  • 34k
6 votes

StringReplace question from "An Elementary Introduction to the Wolfram Language"

Decompose the problem. For example, "Make any 2-letter word uppercase" is a problem that you can probably solve (hint, there is a built in function for that). Now move on to "Make any 2-letter word up …
lericr's user avatar
  • 34k
5 votes

Is it possible to write a faster StringTemplate?

Here's an attempt: MyStringTemplate[form_String][repls__] := With[ {positions = StringPosition[form, "``"], stringRepls = ToString /@ {repls}}, StringReplacePart[form, PadRight[stringRe …
lericr's user avatar
  • 34k
2 votes

creating strings from variable depth lists

I might try MapIndexed. This assumes that each sublist at the first level has length 3. It could be modified if that's not the case. To show how MapIndexed might work, let's test with a dummy function …
lericr's user avatar
  • 34k
3 votes

How to compose a filename with multiple string parameters?

I actually like StringTemplate for these kinds of things. It's nicely reusable as a function, like a curried StringForm (but it produces actual strings at the end). You also have the option of naming …
lericr's user avatar
  • 34k
6 votes

Small trouble with variable referencing in StringReplace?

Let's put your transformation into a function for re-usability: func[str_] := str <> "H" Here's your input: input = "abcdEFGpcf" Now, we can use either string expressions or RegularExpression: Strin …
lericr's user avatar
  • 34k
4 votes

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

In version 13.2 StringRepeat[" ", 0] produces an empty string.
lericr's user avatar
  • 34k

15 30 50 per page