The Artima Developer Community
Sponsored Link

Java Answers Forum
HELP!! first words capitalized

2 replies on 1 page. Most recent reply: Oct 11, 2003 8:44 PM by jung

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
jung

Posts: 5
Nickname: jung
Registered: Oct, 2003

HELP!! first words capitalized Posted: Oct 10, 2003 6:15 PM
Reply to this message Reply
Advertisement
Is someone kindly to help me with this question:
How to display the words input from user with the first letter of all the words capitalized. I only know the meth to convert the entire string to the uppercase, but did not know how to convert for the fist letter and display.
Thanks!!


FredrikN

Posts: 22
Nickname: fredrikn
Registered: Jul, 2003

Re: HELP!! first words capitalized Posted: Oct 11, 2003 1:22 AM
Reply to this message Reply
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;
	}
 
}
 

jung

Posts: 5
Nickname: jung
Registered: Oct, 2003

Re: HELP!! first words capitalized Posted: Oct 11, 2003 8:44 PM
Reply to this message Reply
as a beginner, your code is really helpful,
I did it in another way which take me whole night to
complete. Your code is really professional. Thanks!

Flat View: This topic has 2 replies on 1 page
Topic: package and import Previous Topic   Next Topic Topic: JTable cell editing and event handling

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use