? Seperating text from INPUT into individual letters (Page 1) ● SmileBASIC Source Forums

Sign In

*Usernames are case-sensitive
Forgot my password

Seperating text from INPUT into individual letters

  • #1 ✎ 1 radostin04 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. Posted
  • #2 ✎ 317 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength 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. Posted Edited by spaceturtles
  • #3 ✎ 960 Y_ack Head Admin 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 Posted
  • #4 ✎ 36 Mr_Mo Promoted Page My page was promoted on SmileBASIC Source! Achievements Video Games I like to play video games! Hobbies Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself
    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
    Posted Edited by Mr_Mo