您的位置:首页 > 其它

正则表达式-转义字符

2016-07-27 10:44 274 查看
字符串"1\n2\\n3\n4\\n5",匹配\\n,以下两种方式等价,第二种不容易出错,不用考虑字符串带来的问题,下载jar包

package com.test;

import org.apache.commons.lang3.StringUtils;

public class Test12 {

public static void main(String[] args) {
String ss1 = "1\n2\\n3\n4\\n5";
System.out.println("本身字符串:");
System.out.println(ss1);
String[] array = ss1.split("\\\\n");
for (int i = 0; i < array.length; i++) {
System.out.println("第" + (i + 1) + "个:" + array[i] + "  ");
}
System.out.println();
String[] array1 = StringUtils.splitByWholeSeparator(ss1, "\\n");

for (int i = 0; i < array1.length; i++) {
System.out.println("第" + (i + 1) + "个:" + array1[i] + "  ");
}

}

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: