This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

how to print in capital of each frist word  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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"
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using StringTokenizer and the charAt method of the String class. Check the API.

Bosun
 
deepak singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If u r good at regular expressions, u can do that easily
Try gnu.regexp for java regular expressions
Thanks
Shashank
 
shashank shah
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!