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

Username:   Password: 
 RegisterRegister   
 Convert Lowercase word to upper
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Slayer




PostPosted: Thu Dec 15, 2005 9:19 pm   Post subject: Convert Lowercase word to upper

Basically i need help with writting a program that recieves a a word and converts it to uppercase

ex. input- "Convert"
output- "CONVERT"

i really suck in this area, hopefully someone can help me out..
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Thu Dec 15, 2005 9:22 pm   Post subject: (No subject)

Str.Upper()
Str.Lower()

or else you could always make a program that does it yourself. If you wish to learn how and/or don't have these functions, use Cervantes' String Manipulation tutorial to write your own.
Slayer




PostPosted: Thu Dec 15, 2005 9:27 pm   Post subject: (No subject)

wow amazing.. thx..
Slayer




PostPosted: Thu Dec 15, 2005 9:40 pm   Post subject: (No subject)

funny, i was told to do it this way by someone else..
find the length
compare each individual letter to see if its capitol or not
if its capitol add that character to the newWord
newWord:= newWord + word(i)
if it is not capitol convert to capitols and add it to the newWord
newWord := newWord +ch(ord(word(i))-32)

i must say, i like your way much better
[Gandalf]




PostPosted: Thu Dec 15, 2005 9:50 pm   Post subject: (No subject)

No problem. Well, the way I posted just does the same thing but it is premade. As wtd sometimes says "Don't reinvent the wheel if theres an existing library function to do it for you." This is the case for Str.Upper(), although you might benefit from learning how it works and why.

Here's the real function:
code:
    function Upper (s : string) : string
        var res : string := ""
        for i : 1 .. length (s)
            if "a" <= s (i) and s (i) <= "z" then
                res := res + chr (ord (s (i)) + ord ("A") - ord ("a"))
            else
                res := res + s (i)
            end if
        end for
        result res
    end Upper
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  [ 5 Posts ]
Jump to:   


Style:  
Search: