} } Now I want to print First name and last name seperately. How do I do this? I know I can write code as s.substring(0,4) or vice versa. But if you have a list of names you cant go about writing (0,3) or (0,5) simultaneously. You can seperate the FirstName and LastName from its space. How do you do that? Please help!
Look at the the indexOf method for String. You'll use something like this to find the space seperating the first and last name. And then use that index for your substring calls. Of course this assumes you only have a first and last name and not a middle name as well. If there is a middle name you'll need to find the index for both spaces.
[ April 12, 2006: Message edited by: Hentay Duke ] [ April 12, 2006: Message edited by: Hentay Duke ]
You can use a StringTokenizer to seperate the words. Or another more cumbersome way, (but simpler in terms of helping you learn) would be to get the ASCII value for each character, when the value is equivalent to that of a space,32, then divide the string into substrings from that char as a central pivot. Then you can do whatever you like with them - for instance put them into an array of first names and an array of second names. Then for each entry e.g. in your firstNamesArray will correspond to LastNmaesArray and you can concat. these two values to get the full name.
Hi Guys, i saw there are lot of option are available for your Question . i belive all are correct, but to get the Best one by implementing Regular Expression in the Java Code which has been add in the java 1.5 .. if u have any other query Reply . email@example.com
Regards<br /> <br />Mohammed Yousuff M N <br /> <br />Try NOT to Become a man of SUCCESS, BUT Try to Become a man of VALUE..
posted 12 years ago
...Regular Expression in the Java Code which has been add in the java 1.5...
actually regular expressions were added in 1.4, so if your program will be running on a minimum of java 1.4 you will be able to use them (String.split() and java.util.regex package).
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database