Re: What is "\\s+"



Allan Bruce wrote:

> I am looking through some code which parses csv files, and this is being
> used to split the files. The variable is called separator, but I dont
> know
> what it is, can somebody clarify? What is "\\s+" ??

Something like this?

String separator = "\\s+";
...
String[] items = input.split(separator);

The "\\s+" in the source code gets compiled into the string "\s+", which is
a regular expression meaning one or more whitespace characters. This
behaves similarly to StringTokenizer but more flexibly, since you can use
all the regexp syntax to define the separators.

Take a look at these APIs for more info:
java.lang.String.split()
java.util.regex.Pattern
java.util.regex.Matcher

(BTW, the code above will split the input string between whitespace, not
between commas.)

HTH.

.