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

Username:   Password: 
 RegisterRegister   
 Using String Manipulation to Change a Space to an Underscore
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Four




PostPosted: Tue Jan 20, 2009 5:37 pm   Post subject: Using String Manipulation to Change a Space to an Underscore

Well, I'm creating a game and for my highscore table, when they enter their name, if they enter a space, I want the space to convert to an underscore so the highscores wont get messed up. When I write the code, it says the left side is not a variable and hence cannot be assigned to.

code:

        get strNameSub : *

        for n : 1 .. length (strNameSub)
            if strNameSub (n) = " "
                    then
                strNameSub (n) := "_"
            end if
        end for



Edit: I just tried the code below, but it does not change the space to an underscore

code:
        for n : 1 .. length (strNameSub)
            if strNameSub (n) = " "
                    then
                put "_"
            end if
        end for

Thanks
Sponsor
Sponsor
Sponsor
sponsor
nike52




PostPosted: Tue Jan 20, 2009 7:29 pm   Post subject: Re: Using String Manipulation to Change a Space to an Underscore

try ' ' instead of " "?
TheGuardian001




PostPosted: Tue Jan 20, 2009 8:41 pm   Post subject: Re: Using String Manipulation to Change a Space to an Underscore

the problem is not with the type of quotes. I believe Turing accepts either type of quotes for strings. The problem is that strNamSub(n) is not a variable, it is an index of a variable. you will probably need to totally reset your string to include "_". to reset a string character by character:

code:

for i : 1 .. length of stringName %for every character in the string
newString += stringName(i) %add that character to a new string
end for %end


all you need to do at that point is to check what character is going in before adding it to the new string
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: