Using String Manipulation to Change a Space to an Underscore
Author |
Message |
Four
|
Posted: 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
|
|
|
nike52
|
Posted: Tue Jan 20, 2009 7:29 pm Post subject: Re: Using String Manipulation to Change a Space to an Underscore |
|
|
try ' ' instead of " "? |
|
|
|
|
|
TheGuardian001
|
Posted: 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 |
|
|
|
|
|
|
|