GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes find string with whitespace in between Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "find string with whitespace in between" Watch "find string with whitespace in between" New topic
Author

find string with whitespace in between

James Byars
Ranch Hand

Joined: Apr 15, 2009
Posts: 42
hi,

I have a string that is separated by a delimeter -. I want to basically extract all the values from this string, and check if there is any whitespace between the values.

e.g.

if my string is
hello-world- this - is-me

the values would be
hello
world
this
is
me

and if the string is
hello world- bye-world-hello again world

then the values would be
hello world
bye
world
hello again world

as you can see, in the second example two of the values "hello world", and "hello again world" are separated by whitespaces, and I need to find such values.

thanks

thanks

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Ok first you want to split your string by the dash delimiter. Piece of cake.


As for whitespaces, you'll need to use a regular expression which is '\s'

Check here for reference http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/package-summary.html

JDBCSupport - An easy to use, light-weight JDBC framework -
 
GeeCON Prague 2014
 
subject: find string with whitespace in between