Computer Science Canada

Convert Lowercase word to upper

Author:  Slayer [ 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..

Author:  [Gandalf] [ Thu Dec 15, 2005 9:22 pm ]
Post 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.

Author:  Slayer [ Thu Dec 15, 2005 9:27 pm ]
Post subject: 

wow amazing.. thx..

Author:  Slayer [ Thu Dec 15, 2005 9:40 pm ]
Post 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

Author:  [Gandalf] [ Thu Dec 15, 2005 9:50 pm ]
Post 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


: