Results 1 to 9 of 9
Thread: how to get initials
- 01-02-2012, 06:43 AM #1
Member
- Join Date
- Dec 2011
- Location
- india
- Posts
- 16
- Rep Power
- 0
- 01-02-2012, 08:42 AM #2
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
Re: how to get initials
you can use string buffers but you would need to put a little bit of work into it. here is where i did my tutorial when i first tried a similar thing How to use the Java StringBuffer class - YouTube
-
Re: how to get initials
That's not the purpose of this forum -- to give you the code you desire or to do your assignments for you. Rather we'd be more than happy to help you learn, and so in that vein, why not first try to solve this yourself -- it's not that hard to do, and then if your code works, great, but let us know. If it doesn't then please post your code here with code tags and with any error messages that it might cause, and let's see if we can help you out.
- 01-04-2012, 07:20 AM #4
Member
- Join Date
- Dec 2011
- Location
- india
- Posts
- 16
- Rep Power
- 0
Re: how to get initials
OK
thanks for reply,
i hv tried following code to find initials but that is not working pls solve following .
Java Code:String name = "Abhijit peakash bagal"; StringBuilder sbInitials = new StringBuilder(); String[] nameParts = name.split("\s"); for (String part : nameParts) { sbInitials.append(part.charAt(0)); } String initials = sbInitials.toString();Last edited by Eranga; 01-06-2012 at 03:22 AM. Reason: code tags added
- 01-04-2012, 03:52 PM #5
Re: how to get initials
for starters, you need to use code tags. Secondly, you didn't post your error. Thirdly, you didn't escape your \. Lastly, this program works fine for me!
- 01-05-2012, 09:09 AM #6
Member
- Join Date
- Dec 2011
- Location
- india
- Posts
- 16
- Rep Power
- 0
Re: how to get initials
i am getting error : no escape character (for "\s").
- 01-05-2012, 11:35 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: how to get initials
Do you remember all the escape characters we are using? Is there such character like "\s"?
Did you read about split() in Java DOC?
- 01-05-2012, 03:39 PM #8
Re: how to get initials
Did you read my post? You need to double escape that, so "\s" becomes "\\s". Java doesn't have a \s escape character but regex does. You're writing a regex. So to prevent java from thinking it is an escape character for java, you need to escape the escape character so it gets passed cleanly to regex. In other words, double escape \\s.i am getting error : no escape character (for "\s").
- 01-07-2012, 10:17 AM #9
Member
- Join Date
- Dec 2011
- Location
- india
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
Initials (what am i doing wrong)
By genocist in forum New To JavaReplies: 5Last Post: 05-10-2010, 11:08 PM -
how do i initials the word so i get the first letter only
By mikeitalydz in forum New To JavaReplies: 15Last Post: 04-19-2009, 10:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks