
-----------------------------------
ofcourseitsdan
Thu Feb 23, 2012 10:49 am

whitespacing
-----------------------------------
What is it you are trying to achieve?
Im trying to remove spaces in a string


What is the problem you are having?
removing spaces


Please specify what version of Turing you are using
4.1.1

-----------------------------------
Dreadnought
Thu Feb 23, 2012 12:56 pm

Re: whitespacing
-----------------------------------
What have you tried? What do you consider whitespace?

-----------------------------------
Tony
Thu Feb 23, 2012 4:19 pm

RE:whitespacing
-----------------------------------
What kind of a problem are you having with this? (trying to find where whitespace is; removing a character at a known location; etc)

-----------------------------------
ofcourseitsdan
Fri Feb 24, 2012 9:51 am

Re: whitespacing
-----------------------------------
What have you tried? What do you consider whitespace?

if you read my problem it says i cant remove spaces. ive used this code but it outputs the letters on different lines if the word has spaces. e.g "h e y" outputs 

h
e
y

var word : string
var newword : string := ""

procedure remove_spaces (user_word : string)
    newword := ""

    for x : 1 .. length (word)
        if index (" ", word (x)) = 0 then
            newword += word (x) + ""
        end if
    end for


    put newword
end remove_spaces

loop
    get word

    remove_spaces (word)
end loop


-----------------------------------
Raknarg
Fri Feb 24, 2012 11:08 am

RE:whitespacing
-----------------------------------
newword += word (x) + "" 

get rid of the + ""

-----------------------------------
[Gandalf]
Fri Feb 24, 2012 5:35 pm

RE:whitespacing
-----------------------------------
By default, get word will treat any whitespace as the end of the input.  To include whitespace, up to the maxium string length, use get word : *.  The asterisk is a wildcard meaning take as many characters as possible, however it could be replaced with a number specifying the maximum characters to include in the input.

Also, one suggestion to improve your program: local variables are always better than global variables.  For example:
procedure remove_spaces (user_word : string)
    var newword : string := "" % local, also no redundant assignment

    for x : 1 .. length (word)
        if index (" ", word (x)) = 0 then
            newword += word (x) % unnecessary + "" as mentioned
        end if
    end for


    put newword
end remove_spaces

loop
    var word : string % local, and passed to remove_spaces as a parameter
    get word : * % include whitespace

    remove_spaces (word)
end loop 

-----------------------------------
Raknarg
Fri Feb 24, 2012 8:06 pm

RE:whitespacing
-----------------------------------
Right. Didn't think that one through.
