java用spilt方法分割ip地址

来源:互联网 发布:杭州做公卫软件 编辑:程序博客网 时间:2024/06/09 14:01

必须对"."进行转意

“ . ”在正则表达式中有特殊的含义,因此我们使用的时候必须进行转义。

  1. public static void main(string[] args) {  
  2. string value = "192.168.128.33";  
  3. string[] names = value.split("\\.");  
  4. for (int i = 0; i < names.length; i++) {  
  5. system.out.println(names[i]);  
  6. }}  
或者

String str = "192.0.0.1";  

String[] array = new String[]{};    

array = str.split("[.]");

1 0
原创粉丝点击