Page 1 of 1

split strings into characters

Unread postPosted: 27 Jan 2022, 10:18
by BluStar
Hi to all.
how can I split a string into single characters?
For instance:
"Hello" in
"H"
"e"
"l"
"l"
"o"

Thanks

Re: split strings into characters

Unread postPosted: 27 Jan 2022, 11:06
by SlyVTT
Hello,

you need to iterate through the length of the string and extract each of the character to print it.
This is a short program that do the stuff, but you will need to adjust as per your actual need:

Code: Select all
Define stringsplit()=
Prgm

  "Hello"->str0
  dim(str0)->b

  For i,1,b
    mid(str0,i,1)->ch
    Disp ch
  EndFor

EndPrgm


So first we put the string in the variable str0 and put the length of str0 into the variable b using the dim() function.

Then we iterate through the string with the For loop. At each step, we extract the i-th character with the function mid() and draw the char with Disp.

Not so hard, just need to know the right functions to be used

Ciao

Sly

Re: split strings into characters

Unread postPosted: 27 Jan 2022, 11:23
by BluStar
Thanks