Computer Science Canada

string to integer

Author:  maiku [ Thu Aug 03, 2006 4:05 pm ]
Post subject:  string to integer

I cant figure out how to get a string into an integer Evil or Very Mad . I know it has to be a transferable value like the string has to be "10453" but i cant figure out how to use intstr or strint (whichever i need to use) or strintok, which does something, but i dont know what it does. If there's a tutorial for this, could someone give me the link? or if you know how to do it, could you leave an example? thnx so much

Author:  Mazer [ Thu Aug 03, 2006 4:21 pm ]
Post subject: 

code:
var number : string := "123"
var value : int := strint(number)


I don't know if there's a tutorial for it here... actually, there probably is, but it wouldn't be worth looking through all those pages of tutorials for it.

Pro tip: in Turing, type a function name or keyword, and (with the cursor located on the word), press F9. The Turing reference will pop up and explain things about what you want to use.

Author:  richcash [ Thu Aug 03, 2006 4:36 pm ]
Post subject: 

For strintok, it's a boolean function that tells you whether or not you can change a string into an integer. You know that a string must be convertable, so the strintok returns true when the string is convertible.

code:
var value : string := "324"
if strintok (value) then
     put strint (value)
end if


This is helpful just in case value is something like "dog", then it won't give you an error, since the 'put strint (value)' won't run because strintok returns false in the if statement.

Author:  TokenHerbz [ Fri Aug 04, 2006 3:21 am ]
Post subject: 

im curious to weather or not other variations of "strintok" exist... Id look myself if it wern't time for bed... Smile

Author:  NikG [ Fri Aug 04, 2006 2:45 pm ]
Post subject: 

TokenHerbz wrote:
im curious to weather or not other variations of "strintok" exist... Id look myself if it wern't time for bed... Smile
Just 3 versions I believe, all for converting numbers to strings: strintok, strnatok, strrealok

Author:  Albrecd [ Sat Aug 05, 2006 12:56 pm ]
Post subject: 

If you're trying to get the number value of the characters in your string, use ord.

code:
var word : string := "hello"
put ord (word)
% or
put ord (word (2)) %for a specific letter


: