This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

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.

 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!