Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to get a number with spaces in between as a integer instead of a string
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pinkbob




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
HeavenAgain




PostPosted: 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


Neutral im sure theres better way than this
Clayton




PostPosted: 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 Wink

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
pinkbob




PostPosted: 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!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: