Author |
Message |
pinkbob
|
Posted: Fri Oct 19, 2007 4:37 pm Post subject: 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
HeavenAgain
![](http://compsci.ca/v3/uploads/user_avatars/139122102045e603120b143.jpg)
|
Posted: Fri Oct 19, 2007 5:04 pm Post subject: RE:How to get a number with spaces in between as a integer instead of a string |
|
|
code: | 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 |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Fri Oct 19, 2007 5:12 pm Post subject: 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
Turing: |
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
|
|
|
|
|
|
![](images/spacer.gif) |
pinkbob
|
Posted: Fri Oct 19, 2007 5:15 pm Post subject: RE:How to get a number with spaces in between as a integer instead of a string |
|
|
thanks for the help, really appreciate it! |
|
|
|
|
![](images/spacer.gif) |
|