Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Splitting

 
Shelly Biswal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

i need to split the following string : "//name['firstname = shelly']"
and get output as : firstname
shelly
and then i need to put them in string variables like
nameCategory = firstname and
myName =shelly
how do i do it?
do i need to use multiple split statements?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With String#subString(), get the string between character ' to ' ,
and split the string on regex "=" , then you can go !!

Hope this Help !
 
Taariq San
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sagar Rohankar:
and split the string on regex "=" , then you can go !!


That'll do, I'm not sure what the first line meant but that's enough.

"firstname = shelly".split("=") will give you a String[] with 2 elements, firstname and shelly, you'll just have to remove the whitespace with trim()
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Taariq San:


That'll do, I'm not sure what the first line meant but that's enough.


Look the string to split carefully, its enclosed in " ' " character..


So we need a substring enclosed in that character , once we get it , we can split it on "=",

Hope this clarifies !
 
darshan karle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi shelly,

try to use StringTokenizer class of util package.

regards
darshan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic