Frustrating simple problem.
Hi!
Heres the code:
Code:
public class PopupSample{
public static void main(String args[]){
String s = "int xcomp.XComponent.width";
System.out.println(s.split(".").length);
}
}
As you can see, the string have 2 dots in it.
It will claim to be NO dots at all when you run this.
What is the problem?! Dot is not a special character that needs some sort of @£@$@£$\\@ . to be interpreted as a dot!
So why wont this simple split action work?
Re: Frustrating simple problem.
you need to escape the period.
Code:
System.out.println(s.split("\\.").length);
Re: Frustrating simple problem.
Quote:
Originally Posted by
Addez
What is the problem?! Dot is not a special character that needs some sort of @£@$@£$\\@ . to be interpreted as a dot!
So why wont this simple split action work?
A dot is special for the regular expression engine use by the split( ... ) method; a dot means 'any character' and you don't want that. The regular expression syntax wants you to escape the special meaning of that dot (meta) character so you should use "\\." instead of "." the double backslash is needed to keep Javac happy.
kind regards,
Jos