
-----------------------------------
noobsauce
Sun Nov 09, 2008 6:24 pm

string to integer?
-----------------------------------
Ok, I am to make a program that askes the user to enter his name and then separate him into 2 catagories according to his first letter of last name. I want to convert the letter into integer and use the ASCII table to find what it is. But i can't convert it to integer...? here is my code so far


var username : string (100)
var counter, lastname: int := 0
put "Please enter you name: "..
get username : *
loop
counter := counter + 1
exit when username(counter) = username(*)   %donno if this works perfectly
end loop
loop
counter := counter - 1
exit when username(counter) = ' '
end loop
put username(counter+1)
lastname := strint (username(counter+1))        %error on this line
put lastname

Is there a special function to do it? I tried to do it directly:

lastname := username(counter+1)

it says error anyways...

Mod Edit: Please remember Code Tags. Thanks [code]Code here[/code]  

-----------------------------------
TheGuardian001
Sun Nov 09, 2008 7:36 pm

Re: string to integer?
-----------------------------------
there is actually a command built into the language used for this.

number := ord(letter)
letter := chr(number)

ord goes from a letter to its ASCII character, while chr does the opposite and converts ASCII codes into letters.

-----------------------------------
noobsauce
Sun Nov 09, 2008 8:35 pm

Re: string to integer?
-----------------------------------
Thanks it works, but how do i fix 

exit when username(counter) = username(*)

It doesn't work if the last letter was repeated in the name

-----------------------------------
pavol
Sun Nov 09, 2008 10:29 pm

Re: string to integer?
-----------------------------------
I am assuming that your code:
loop
    counter := counter + 1
    exit when username (counter) = username (*)
end loop
is used for finding the length of the username string. An easier way of doing this is to simply write:
counter := length(username)
