• Post Reply Bookmark Topic Watch Topic
  • New Topic

spliting string  RSS feed

 
vara prasad
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can u send me code to validate sentance;
means:-
user will give sentance like

"java,j2ee servlets / jsp & util package"

then i want result like

'java','j2ee','servlets','jsp','util','package'
i want to elemenate spaces,tabs, ',' , / ? * & like things
 
Scheepers de Bruin
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try:

String resultString = myString.replaceAll("[\\s|\\W]*", ",");
(Note the escaping of the \ i.e. \\)

This returns a String that has all sequences of whitespace (\s) or (|) non-word characters (\W - basically everything except a-zA-Z_0-9) replaced with ","

Now we can split it up:
String[] splitup = resultString.split(",");

We also could do it like:
String[] splitup = myString.replaceAll("[\\s|\\W]*", ",").split(",");
[ August 25, 2005: Message edited by: Scheepers de Bruin ]
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!