Source language: Translate to:

Navigating String letters

General questions about NeoBook

Moderator: Neosoft Support

Navigating String letters

Postby Cuttlas » Sat Jun 14, 2014 11:58 am

I want to check every letter and digit in a string, but it seems it will show nothing!
Here is a code, I think it should show every letter of [Text] variable in message box, but I only get empty message box. where is wrong with my code?

Code: Select all
SetVar "[Text]" "SomeTextHere"
StrLen "[Text]" "[TL]"
Loop "1" "[TL]" "[Loop]"
MessageBox "" "[Text[Loop]]" "ok" ""
EndLoop
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Re: Navigating String letters

Postby Cuttlas » Sat Jun 14, 2014 12:01 pm

I think [Text[Loop]] will work as an array, But I need to use it as a string :(
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Re: Navigating String letters

Postby Cuttlas » Sat Jun 14, 2014 12:04 pm

I have found a trick, if you know a better way please share it with me :)


Code: Select all
SetVar "[Text]" "SomeTextHere"
StrLen "[Text]" "[TL]"

Loop "1" "[TL]" "[Loop]"
SubStr "[Text]" "[Loop]" "1" "[Letter[Loop]]"
EndLoop

Loop "1" "[TL]" "[Loop]"
MessageBox "" "[Letter[Loop]]" "ok" ""
EndLoop
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Re: Navigating String letters

Postby Gaev » Sat Jun 14, 2014 12:35 pm

Cuttlas:

[Text[Loop]] will NOT give you the Loopth letter in the string Text ... if Text was an array variable, it would give you the Loopth element of the array.

if you know a better way please share it with me
If you don't need each letter/digit as a separate element in an array, try this ...
Code: Select all
SetVar "[Text]" "SomeTextHere"
StrLen "[Text]" "[TL]"
Loop "1" "[TL]" "[Loop]"
    SubStr "[Text]" "[Loop]" "1" "[ThisCharacter]"
    MessageBox "Character at position [Loop] in [Text] ..." "[ThisCharacter]" "ok" ""
EndLoop
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 3 guests