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

Username:   Password: 
 RegisterRegister   
 String Splicing for Information.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
copthesaint




PostPosted: Wed Jul 22, 2009 7:48 pm   Post subject: String Splicing for Information.

I was working on this when I had gotten a very odd logical error. Every line is explained so it should be easy to understand what I made.
It would be very helpful if someone were to help me solve my error. Please donot post unless advice for myself such as using parameters, for
what I'm making, This is the best way to go. Thanks to whom ever spends any time trying to help me. Good Luck Wink

Turing:
View.Set ("Text")

var String : string := "%Music:HotNCold.Mp3,Picture:Backround.jpg"
var SentInfo : array 1 .. 10 of
    record
        String, LoadFile : string
        Type : int
    end record

var num : int := 0
/*For variable i, 1 to the length of the variable String*/
for i : 1 .. length (String)
    /*If Char (i) of String is = to th char "," or the loop just starts, then*/
    if String (i) = "," or i = 1 then
        /*Increases the Count*/
        num += 1
        /*Sets the Default Value*/
        SentInfo (num).String := ""
        /*for the variable p, the value of i +1  to the length of the variable String*/
        for p : (i + 1) .. length (String)
            /*Exits the for loop when Char (p) of String is = to ","*/
            exit when String (p) = ","
            /*Adds the the (p) char from the variable String to the information String*/
            SentInfo (num).String += String (p)
            /*If the information string is of type "Music" then */
            if SentInfo (num).String = "Music:" then
                /*Sets an initial value to the information variable*/
                SentInfo (num).String := ""
                /*for the variable z, the value of the variable p + 1 to the length of the variable String*/
                for z : (p + 1) .. length (String)
                    /*Exits the for loop when Char (z) of String is = to ","*/
                    exit when String (z) = ","
                    /*Adds the the (z) char from the variable String to the information String*/
                    SentInfo (num).String += String (z)
                end for
                /*If the information string is of type "Picture" then*/
            elsif SentInfo (num).String = "Picture:" then
                /*Sets an initial value to the information variable*/
                SentInfo (num).String := ""
                /*for the variable z, the value of the variable p + 1 to the length of the variable String*/
                for z : (p + 1) .. length (String)
                    /*Exits the for loop when Char (z) of String is = to ","*/
                    exit when String (z) = ","
                    /*Adds the the (z) char from the variable String to the information String*/
                    SentInfo (num).String += String (z)
                end for
            end if
        end for
    end if
end for

put num
put "The error is tht it adds it's self even though the count is only two. Any help?"
put SentInfo (1).String
put SentInfo (2).String
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Jul 22, 2009 9:04 pm   Post subject: RE:String Splicing for Information.

If you're just wanting to split strings around a given delimiter, then I've already solved that problem for you. Just use download the String.t file, include it and you can use a String with a StringTokenizer to split an arbitrary string around another arbitrary string...just like in a real language!
copthesaint




PostPosted: Thu Jul 23, 2009 3:32 pm   Post subject: Re: String Splicing for Information.

Ok I see none have soved the problem anyways, I knew I was missing somethin small, He is the fixed code without comments. I just forgot 2 exit statements.

Turing:

var SentInfo : array 1 .. 10 of
        record
            String : string
            Type : int
        end record

proc Split (String : string)
        var num : int := 0
        for i : 1 .. 10
            SentInfo (i).String := ""
            SentInfo (i).Type := 0
        end for
        for i : 1 .. length (String)
            if String (i) = "," or i = 1 then
                num += 1
                for p : (i + 1) .. length (String)
                    exit when String (p) = ","
                    SentInfo (num).String += String (p)
                    if SentInfo (num).String = "Music:" then
                        SentInfo (num).String := ""
                        SentInfo (num).Type := 1
                        for z : (p + 1) .. length (String)
                            exit when String (z) = ","
                            SentInfo (num).String += String (z)
                        end for
                        exit
                    elsif SentInfo (num).String = "Picture:" then
                        SentInfo (num).String := ""
                        SentInfo (num).Type := 2
                        for z : (p + 1) .. length (String)
                            exit when String (z) = ","
                            SentInfo (num).String += String (z)
                        end for
                        exit
                    end if
                end for
            end if
        end for

        for i : 1 .. num
            put SentInfo (i).String
        end for
end Split
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  [ 3 Posts ]
Jump to:   


Style:  
Search: