Computer Science Canada Clearing spaces in a string |
Author: | MysticVegeta [ Fri Apr 08, 2005 3:50 pm ] |
Post subject: | Clearing spaces in a string |
Ok, Now if i have a string "QW QW WQ WQ" How do i make it like this "QWQWWQWQ" I tried using index and substrings but the thing is i dont know after how many words are spaces located and they are random in strings. No pattern. Is there a command for it? Or a manual method? Thanks |
Author: | Cervantes [ Fri Apr 08, 2005 4:05 pm ] | ||
Post subject: | |||
What have you got so far? There are a few tricks in this problem. First, do you know how to find a space? Next, how far have you got? Post code! ![]() If you haven't got this already, here's a hint.
But there's more to it than that. |
Author: | Unreal_Origin [ Fri Apr 08, 2005 4:15 pm ] | ||
Post subject: | |||
here it is
there is probably another way to do it but this is what i made |
Author: | Drakain Zeil [ Fri Apr 08, 2005 4:17 pm ] | ||
Post subject: | |||
You could make a loop for 1... length of the string then go newstring+=oldstring ONLY if the position in the string is not a " ". You can pull out parts of a string by specifying placement in brackets. ie.
these output: "i" "i my n" "hi my name is bob" So just use a check for 1.. string length, if it is equal to a space do nothing, else, add on the letter to the string. |
Author: | Bacchus [ Sat Apr 09, 2005 1:03 am ] |
Post subject: | |
i think the point was to let them figure it out by themselves. the best way i can think of is Cervantes way, which also was a question in that stupid turing book if i remember right. the point is to use index to find the position of the space then set the word to the word leading up to the space (space-1) then add the rest of the word after the space (space+1) and keep repeating that until index returns 0 saying that there wasnt ne more space in there. this way would go faster (i think) cause then it doesnt have to go searching through every single character of the string and checking to se if it was a space |
Author: | MysticVegeta [ Sun Apr 10, 2005 7:05 pm ] | ||
Post subject: | |||
yea i read, i came up with something like this->
|