0
|
5657 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
GROUPS:

# String Manipulation: How do you split a string of data?

Posted 9 years ago
 I am fairly new to mathematica. I am trying to split a string and output it as triplets. I have tried playing with the StringSplit, Split, and Partition functions to no avail. Here is a sample: [IN] "955929400769971" [OUT] 955 929 400 769 971 Any ideas would be appreciated.
4 Replies
Sort By:
Posted 9 years ago
 This is similar to Nasser's answer, but using Riffle instead of Insert: In[1]:= StringJoin@Riffle[Partition[Characters@"955929400769971",3]," "] Out[1]= 955 929 400 769 971 
Posted 9 years ago
 Just for fun: StringCases[ "955929400769971", Repeated[_, {3}] ]  {"955", "929", "400", "769", "971"}
Posted 9 years ago
 Thank you Nasser. That worked like a champ. Now to the docs to analyze what you did ;). I appreciate the assistance.
Posted 9 years ago
 one way might be str = "955929400769971"; c = Partition[Characters[str], 3]; c = Insert[#, " ", -1] & /@ c; StringJoin[StringJoin[#] & /@ c] Which gives "955 929 400 769 971 " And if you just want the strings in a list: str = "955929400769971"; c = Partition[Characters[str], 3]; StringJoin[#] & /@ c gives {"955", "929", "400", "769", "971"}