国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Java中使用split分解IP地址

2022-12-07 11:14 作者:IP數(shù)據(jù)云  | 我要投稿

日前在使用split 分解字符串時,發(fā)現(xiàn)"."這個字符串分解不了,程序如下:

public static void main(String[] str){

String ip = "59.39.158.107";

String[] ipstr = ip.split(".");?

System.out.println(ipstr.length);

}

免費查IP歸屬地?https://www.ipdatacloud.com/?utm-source=LJ&utm-keyword=?1088

后來查看了String.split的源碼,明白split是用正則來分解的,然而"."在正則是特殊字符,所以得用轉義符來轉義

String.split的源碼如下:

public string[] split(string regex, int limit) {

return pattern.compile(regex).split(this, limit);

}

修改后的分解IP程序如下:

public static void main(String[] str){

String ip = "59.39.158.107";

String[] ipstr = ip.split(".");

System.out.println(ipstr.length);

}

可以發(fā)現(xiàn)加入后可以正確的分解字符串

Java中使用split分解IP地址的評論 (共 條)

分享到微博請遵守國家法律
克拉玛依市| 永清县| 泗阳县| 新余市| 栖霞市| 元江| 玉山县| 寻乌县| 靖宇县| 柯坪县| 绥宁县| 江源县| 厦门市| 苗栗市| 阜城县| 什邡市| 启东市| 临潭县| 宿松县| 喜德县| 大同市| 汉川市| 鄂温| 浦东新区| 丹寨县| 乌什县| 合阳县| 达州市| 张北县| 宽城| 白银市| 清水河县| 连山| 东辽县| 山西省| 富宁县| 乌鲁木齐市| 淳化县| 两当县| 班戈县| 开化县|