• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic