Question

Maybe this is the wrong website to ask, but hopefully somebody knows...

How do I break a string in Maple and store it in a list of substrings?

i.e. my string is : "i love the weekends"

and I want to break it into substrings of size 2... so i would look like this

substrs;

substrs = [[i ][lo][ve][ t][he][ w][ee][ke][nd][s ]]

Was it helpful?

Solution

LengthSplit in the StringTools package seems to do what you want:

substrs := StringTools[LengthSplit]("i love the weekends", 2);

OTHER TIPS

this works great! How would you convert it to a list though? – user69514 Apr 20 '09 at 17:36

Simple, just put a list constructor around it:

substrs := [StringTools[LengthSplit]("i love the weekends", 2)];
s := "abcdefghijklmnopqrstuvwxyz";
s[1..2];
seq(s[i..i+1], i=1..length(s), 2);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top