class RegexDemo{
public static void main(String[] args){
String str = "abcd efghi klmn";
String[] strArr = str.split("\\S");
for(String str1: strArr)
System.out.println("1"+str1);
}
}
it prints 10 times "1". can you please explain how this is working. i think it shoud print "1" 13 times.
thanks
please read the String.split(String) and String.split(String,int) documentation
http://java.sun.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String)
and it's more helpfull to do thisSystem.out.println("'" + str1 + "'");
Message was edited by:
S_i_m_u
> please read the String.split(String) and
> String.split(String,int) documentation
> http://java.sun.com/javase/6/docs/api/java/lang/String
> .html#split(java.lang.String)
>
> and it's more helpfull to do
> thisSystem.out.println("'" + str1 +
> "'");
>
Spoilsport!
> i didn't saying anything wrong.
yes you did
> i've already read the documentation of Pattern and split() method.
read it again, this time with your brain ON.
> I could not understand what is a non-whitespace character.
do you perhaps understand what a non-intelligent person is?
> If someone could explain how the compiler is spliting with delimeter > \\S in my example, that would clear my doubt.
the compiler doesn't splite anything. if you wrote a couple more examples and thought about the output, your doubt would be cleared. at that point, you might even understand why the first reply did give you an answer
> if he's the boss, then i sincerely ask for apology.
> I'm extremely sorry quitte
I'm not the boss - there is no boss. Your response to quitte's response was well out of order. quitte was asking a very valid question which for some reason you felt the need to attack.
Since I am now known to not be the boss do you still apologize to quitte?
I got this stuff from the API document boss. I understand that \\s represents whitespace. space, tab, line, and form-feed. but i dont understand how it behaves in case of \\S
class RegexDemo{
public static void main(String[] args) {
String str = "abcdefghijklm";
String[] strArr = str.split("\\S");
for(String str1:strArr)
System.out.println("1"+str1);}
}
in this case, it doesn't print anything. but if i change
str = "abcd efghi jklm"
then , it prints "1" 10 times.
please explain.
> I got this stuff from the API document boss. I
> understand that \\s represents whitespace. space,
> tab, line, and form-feed. but i dont understand how
> it behaves in case of \\S
>
> class RegexDemo{
> public static void main(String[] args) {
>String str = "abcdefghijklm";
> String[] strArr = str.split("\\S");
> for(String str1:strArr)
>System.out.println("1"+str1);}
> ode]
>
> in this case, it doesn't print anything. but if i
> change
> [code]str = "abcd efghi jklm"
> then , it prints "1" 10 times.
>
> please explain.
Not until you apologize to 'quitte' knowing that I am not in charge.
> ok. i apologize quitte if i hurt you in any manner.
> sorry......
The javadoc for split(String regex) is
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#split(java.lang.String)
which is equivalent to
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#split(java.lang.String,%20int)
with a second parameter of zero which means that trailing fields with zero width are discarded.
Edit: of course no thanks are necessary.
Message was edited by:
sabre150