Here, an example, that does not work with split:
code:
public class TestSplitIP {
public static void main(String[] args) {
String request = "REJECT 172.16.12.100";
String[] sip = request.split(" ");
System.out.println(sip[0] + "-" + sip[1]);
// result: REJECT-172.16.12.100
IP ip = new IP(sip[1]);
System.out.println(ip);
// result: IP: 0.0.0.0
// What shit is here?????
}
}
class IP {
int[] ip = new int[4];
public IP(String str) {
System.out.println(str);
// result: 172.16.12.100
String[] sip = str.split(".");
System.out.println("sip.length = " + sip.length);
// result: sip.length = 0
// ???????????
for (int i = 0; i < sip.length; ++i) {
ip[i] = Integer.parseInt(sip[i]);
}
}
public String toString() {
String tmp = "";
for (int i = 0; i < 4; ++i) {
tmp = tmp + ip[i] + ((i == 3) ? "" : ".");
}
return "IP: " + tmp;
}
}
Редактировал antiw (16.08.2005 02:19)