Re: What is "\\s+"
- From: Adam Funk <a24061@xxxxxxxxx>
- Date: Mon, 05 Dec 2005 12:32:16 +0000
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.
.
- References:
- What is "\\s+"
- From: Allan Bruce
- What is "\\s+"
- Prev by Date: What is "\\s+"
- Next by Date: Re: What is "\\s+"
- Previous by thread: What is "\\s+"
- Next by thread: Re: What is "\\s+"
- Index(es):