• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

spliting string

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic