Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Operations

 
ssasi kumar
Greenhorn
Posts: 26
Chrome Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ssasi kumar
Greenhorn
Posts: 26
Chrome Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at string functions like substring(..) , indexOf(..) , lastIndexOf(..) , charAt(..) etc.

For example , the below code will print 1.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why not use toArray() ... if regex is not what you are looking for
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because String does not have a toArray() method perhaps?
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12183
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
prem pillai
Ranch Hand
Posts: 87
Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ssasi kumar wrote: . . . split string using some key words such as stringtokenizer and split functions. . . .
Careful. Those aren't keywords.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic