
-----------------------------------
pinkbob
Fri Oct 19, 2007 4:37 pm

How to get a number with spaces in between as a integer instead of a string
-----------------------------------
I tried 
var number : string := "123 309 358"
var value : int := strint(number)

but it doesn't work because there are spaces in between the string.
thanks.

-----------------------------------
HeavenAgain
Fri Oct 19, 2007 5:04 pm

RE:How to get a number with spaces in between as a integer instead of a string
-----------------------------------
var numberString : string := "123 123 123"
var num : string := ""
var numbered : int
for i : 1 .. length (numberString)
    if numberString (i) not= " " then
        num += numberString (i)
    end if
end for
numbered := strint (num)
put numbered


:| im sure theres better way than this

-----------------------------------
Clayton
Fri Oct 19, 2007 5:12 pm

RE:How to get a number with spaces in between as a integer instead of a string
-----------------------------------
There is! Make that a function that you can use over and over again ;)


function strip (numberString : string) : int
    var resultString : string := ""
    for i : 1 .. length (numberString)
        if numberString (i) ~= " " then
            resultString += numberString (i)
        end if
    end for
    if strintok (numberString) then
        result strint (numberString)
    else
        result 0
    end if
end strip


-----------------------------------
pinkbob
Fri Oct 19, 2007 5:15 pm

RE:How to get a number with spaces in between as a integer instead of a string
-----------------------------------
thanks for the help, really appreciate it!
