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.
Seperating text from INPUT into individual letters
Root / Programming Questions / [.]
radostin04Created:
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] NEXTPUSH 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.