| Author |
String Operations
|
ssasi kumar
Greenhorn
Joined: Feb 23, 2011
Posts: 21
|
|
Hi Everybody,
i have doubt from string operations. that is normally we can split string using some key words such as stringtokenizer and split functions. But now i want spliting string using general string concepts insteadof stringtokenizer and split keywords.
with regards,
sasikumar
thanks to advane
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
Hi,
Welcome to CodeRanch!
I'm not quite sure what you might mean by "general string concepts", but perhaps you're thinking of regular expressions? Have a look at the java.util.regex.Pattern class to see if that will meet your needs.
|
[Jess in Action][AskingGoodQuestions]
|
 |
ssasi kumar
Greenhorn
Joined: Feb 23, 2011
Posts: 21
|
|
hi guys,
ok i will check java.regex package. but generally using java.regex package concept are understanding java experts only. so if you dont mind how do working normal string concepts using perform to stringtokenizer functions .
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
ssasi kumar wrote: normal string concepts.
Again, I have no idea what you mean by this. Maybe an example would help me?
|
 |
prem pillai
Ranch Hand
Joined: Nov 02, 2007
Posts: 87
|
|
Have a look at string functions like substring(..) , indexOf(..) , lastIndexOf(..) , charAt(..) etc.
For example , the below code will print 1.
|
 |
Lalit Mehra
Ranch Hand
Joined: Jun 08, 2010
Posts: 369
|
|
|
why not use toArray() ... if regex is not what you are looking for
|
http://plainoldjavaobject.blogspot.in
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Because String does not have a toArray() method perhaps?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Lalit Mehra
Ranch Hand
Joined: Jun 08, 2010
Posts: 369
|
|
Rob Spoor wrote:Because String does not have a toArray() method perhaps?
what about ... toCharArray() ...
i was just trying to put the logic up not the exact method name ...
anyways thanks Rob ...
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
toCharArray() should only be used if you really need a char[], because it creates a new char[]. If you only need to access characters from the String you should use length() and charAt(int) instead.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9948
|
|
prem pillai wrote:Have a look at string functions like substring(..) , indexOf(..) , lastIndexOf(..) , charAt(..) etc.
For example , the below code will print 1.
What about this is unclear? What would you expect this to print? Why do you think this is wrong? We can't help you if you don't explain what you think the problem is.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
prem pillai
Ranch Hand
Joined: Nov 02, 2007
Posts: 87
|
|
fred rosenberger wrote:
What about this is unclear? What would you expect this to print? Why do you think this is wrong? We can't help you if you don't explain what you think the problem is.
I am clear about what I have pasted in this thread .... but looks like you are not at all clear about "who is asking for help ?" & "what is he asking for ?"
The person who initiated this thread is asking for various ways to split a string without using Stringtokenizer or split() method etc
Anyways thanks for asking me so many questions
Peace
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
ssasi kumar wrote: . . . split string using some key words such as stringtokenizer and split functions. . . .
Careful. Those aren't keywords.
|
 |
 |
|
|
subject: String Operations
|
|
|