Finding alphabets in a string

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2008
Posts: 1
Reputation: real thinkers is an unknown quantity at this point 
Solved Threads: 0
real thinkers real thinkers is offline Offline
Newbie Poster

Finding alphabets in a string

 
0
  #1
Mar 25th, 2009
I want to make a program that find the alphabets present in the string using java language.
e-g
i hava a string " Hello World "
It display me that charactes present in it are

H
e
l
0
w
r
d

It count a character only once.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Finding alphabets in a string

 
0
  #2
Mar 25th, 2009
only the alpha characters?

so H3ll0 Wor7D would print out:

H
l
l
W
o
r
D


that's easy enough to do using regular expressions.

the [a-zA-Z] searches for all characters within the range of a-zA-Z. You can then use the regexp to output the matches...etc
Last edited by Killer_Typo; Mar 25th, 2009 at 3:49 pm.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Finding alphabets in a string

 
0
  #3
Mar 25th, 2009
^ No, he's saying only to print out the character the first time it is seen.

RealThinkers, what you should do is make an array of 26 booleans, one for each letter in the alphabet. True means it has been seen, false means it hasn't. Then when you see a character, if it is a letter, check the corresponding index to see whether or not it has been seen yet. Make sure to set it to 'seen'/true after you see the char for the first time.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Finding alphabets in a string

 
0
  #4
Mar 25th, 2009
Originally Posted by BestJewSinceJC View Post
^ No, he's saying only to print out the character the first time it is seen.

RealThinkers, what you should do is make an array of 26 booleans, one for each letter in the alphabet. True means it has been seen, false means it hasn't. Then when you see a character, if it is a letter, check the corresponding index to see whether or not it has been seen yet. Make sure to set it to 'seen'/true after you see the char for the first time.
hah I had missed his

it count character only once
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Finding alphabets in a string

 
0
  #5
Mar 25th, 2009
Or just step through and add every letter to a Set.
Last edited by Ezzaral; Mar 25th, 2009 at 10:17 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC