as input my program gets a String containing IP Addresses are separated by a line delimiter, i.e. one IP Address per line. To validate each of the addresses I do:
String[] temp;
temp = address.split(System.getProperty("line.separator"));
and then I loop though the array of Strings.
I was wondering why all but the last IP Address were always invalid. I’ve found out, that they look like 10.1.1.1^M
Is there a way to tell the java.lang.String.split to drop the delimiter before putting the token into the array? Or what other options do I have here? Sorry, I’m not a Java Ninja, so I thought I’ll ask you guys before I start googling for hours.
Thanks
Thomas
The problem is that the delimiter in your file is
"\r\n", but the value ofSystem.getProperty("line.separator")is"\n". This means that the"\r"is not treated as part of the delimiter.