aspose file tools*
The moose likes Java in General and the fly likes how to print in capital of each frist word Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to print in capital of each frist word" Watch "how to print in capital of each frist word" New topic
Author

how to print in capital of each frist word

deepak singh
Greenhorn

Joined: Sep 03, 2001
Posts: 4

can any one write a small program to print capital letter of each word.
for example="this sentance i have to put in capital";
out put i want is
"This Sentance I Have To Put In Capital"
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Try using StringTokenizer and the charAt method of the String class. Check the API.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
deepak singh
Greenhorn

Joined: Sep 03, 2001
Posts: 4
hi Bosun Bello,
i know that i will get by that ,as i have writen this program
"
import java.util.*;
public class capitalizingString
{
public static String capatilize(String str)
{
StringTokenizer st=new StringTokenizer(str,"");
StringBuffer sb=new StringBuffer();
if(st.hasMoreElements())
{
String e1= (String)st.nextElement();
if(int i=0;i<st.countTokens();i++)>
{
sb.append(Character.toUpperCase(e1.charAt(i)));
sb.append(e1.substring(1)+ "");
}
}
return sb.toString();
}
public static void main(String arg[])
{
String s="this is the sentance which u have to do capitalize";
String s1=capatilize(s);
System.out.println("result of capitalizing;"+s1);
}
}
"
after running this i am geting only frist letter capital
outPut is
"This is the sentance which u have to do capitalize"
but i what out put
"This Is The Sentance Which U Have To Do Capitalize"
shashank bapat
Ranch Hand

Joined: Jul 11, 2001
Posts: 69
If u r good at regular expressions, u can do that easily
Try gnu.regexp for java regular expressions
Thanks
Shashank


-Shashank<BR>MS(CS),BS(CS),SCJP2
shashank bapat
Ranch Hand

Joined: Jul 11, 2001
Posts: 69
Originally posted by deepak singh:

StringTokenizer st=new StringTokenizer(str,"");

deepak,
i am not sure if its htmlization thats causing it; but ur delim should be space and not empty string or u can use single argument constructor.

 
wood burning stoves
 
subject: how to print in capital of each frist word