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

Username:   Password: 
 RegisterRegister   
 whitespacing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ofcourseitsdan




PostPosted: Thu Feb 23, 2012 10:49 am   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Thu Feb 23, 2012 12:56 pm   Post subject: Re: whitespacing

What have you tried? What do you consider whitespace?
Tony




PostPosted: Thu Feb 23, 2012 4:19 pm   Post subject: 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)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ofcourseitsdan




PostPosted: Fri Feb 24, 2012 9:51 am   Post subject: Re: whitespacing

Dreadnought @ Thu Feb 23, 2012 12:56 pm wrote:
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

Turing:
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




PostPosted: Fri Feb 24, 2012 11:08 am   Post subject: RE:whitespacing

newword += word (x) + ""

get rid of the + ""
[Gandalf]




PostPosted: Fri Feb 24, 2012 5:35 pm   Post subject: 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:
Turing:
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




PostPosted: Fri Feb 24, 2012 8:06 pm   Post subject: RE:whitespacing

Right. Didn't think that one through.
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  [ 7 Posts ]
Jump to:   


Style:  
Search: