FredrikN
Posts: 22
Nickname: fredrikn
Registered: Jul, 2003
|
|
Re: HELP!! first words capitalized
|
Posted: Oct 11, 2003 1:22 AM
|
|
Hello I wrote this method called toUpper, it's a static one.
I you write
"hello my name is fredrik"
it will give you
"Hello My Name Is Fredrik"
It will simply take a string and then return a converted string, the method:
import java.util.*;
public class Convert
{
public static String toUpper(String input)
{
String tmp = Character.toString((input.charAt(0))).toUpperCase();
for(int z = 1 ; z < input.length() ; z++)
{
if(Character.toString(input.charAt(z-1)).equals(" "))
{
tmp = tmp + Character.toString((input.charAt(z))).toUpperCase();
}
else
{
tmp = tmp + Character.toString((input.charAt(z)));
}
}
return tmp;
}
}
|
|