I have a list:
lis = {"20","ab","Cd","10","E"}
in which I would like to join adjacent elements if they are letters and not digits, to give:
res = {"20","abCd","10","E"}
Again thanks for any help!
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityMaybe something like this:
StringJoin /@ SplitBy[lis, LetterQ]
Edit
That doesn't work if there are adjacent non-letter strings. Try this instead:
If[AllTrue[#, LetterQ], StringJoin[#], Splice[#]] & /@ SplitBy[lis, LetterQ]
Another option:
Flatten[SequenceSplit[lis, {str__?LetterQ} :> StringJoin[str]]]
lis = {"20", "ab", "Cd", "10", "E"}
Using SequenceReplace
:
SequenceReplace[lis, {s__String?(StringFreeQ[DigitCharacter])} .. :>
StringJoin@s]
{"20", "abCd", "10", "E"}