Seperating text from INPUT into individual letters
#1✎ 1radostin04Hey 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.
#2✎ 317spaceturtlesVideo GamesI like to play video games!HobbiesAvatar BlockI didn't change my avatar for 30 days.WebsiteIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthOne 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 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.
#3✎ 960Y_ackHead AdminYou 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"
#4✎ 36Mr_MoPromoted PageMy page was promoted on SmileBASIC Source!AchievementsVideo GamesI like to play video games!HobbiesZelda Is Awesome!I love The Legend Of Zelda!Express Yourself
DIM EACHCHAR'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)
instead at the top, or you will get an error