Simple (?) Parser

Blitz3D Forums/Blitz3D Beginners Area/Simple (?) Parser

GrayKnight2k(Posted 2007) [#1]
Hello,

I am trying to create a function that will look through a string and return values based on the characters present in the string.

For example, I have the following name stored in playername$.

 playername$ = "Mouse" 


Basically, I want the code to look through each letter, and return a number based on the letter. If letter = M, return "2"; if letter = "o" return "6"; if letter = "u" then return "12" and so forth. Eventually I want it to look like this:

Mouse
261245

I am pretty sure it is just a matter of incorporating the Len command with a few others, but I am not really sure where to begin.

Any suggestions are much appreciated. Thanks.


Rob Farley(Posted 2007) [#2]
newstring$ =""

for n=1 to len(playername)

c$ = lower(mid(playername,n,1))

if c = "m" then newstring=newstring + "2"
if c = "o" then newstring=newstring + "6" 

etc

next


or better still

Dim Convert(26)
convert(1) = 5 ; A = 5
convert(2) = 10 ; B=6
etc
; Probably best as a data statement

newstring$ =""

for n=1 to len(playername)

newstring = newstring + convert( asc(upper(mid(playername,n,1))) - 64)

next


Note... Totally untested.. Might have to make newstring=" " to force it to be a string first then chop off the first character.


GrayKnight2k(Posted 2007) [#3]
Thanks for the ultra fast response, .Rob. I will play around with this and see what I can come up with.

Gk2k