LoginLogin

Seperating text from INPUT into individual letters

Root / Programming Questions / [.]

radostin04Created:
Hey y'all. I've been trying to get text from INPUT seperated into seperate letters, but I just haven't been able to figure out how to. I'm sorry if this is a stupid question, I'm new to SmileBASIC.

One way to split a string apart is to use a string like an array and put each char into its own string, such as an element of a string array but there isn't much use for that since a string can be used as an array by itself. But here's some code which can do that:
FOR I=0 TO LEN(INPUT_STRING$)-1
 PUSH CHAR_ARR$,INPUT_STRING$[I]
 NEXT
PUSH is used to add another string to the array. To reuse that code and be able to start with an empty string array you'll have to clear the array. One way is to use POP. If you're trying to run comparison on each char you can use IF INPUT_STRING$=="whatever char" THEN ... which is also used in a loop. You can also check for more than one char (a segment of the string) by using LEFT$, RIGHT$, and MID$. With Shelly's example you'll have to resize the EACHCHAR$ array to the length of the string.

You probably don't need to "separate" it, since strings are char arrays anyway (even in smilebasic, if a little weird):
VAR IN$ = "Eiki Shiki, Yamaxanadu"
PRINT IN$[0]
'E
PRINT IN$[1]
'i

DIM EACHCHAR[10]'Each character from the input is stored in an array element.
INPUT "This is the text to display";INPUT$
FOR I=0 TO (LEN(INPUT$)-1)
EACHCHAR$[I]=INPUT[I]
NEXT
do
DIM EACHCHAR$[10]
instead at the top, or you will get an error