2007-10-03
String.split 一些特殊符号的输入情况
public class StringSplit
{
public static void main(String[] args)
{
String str1 = "aa.bb.cc.dd.ee";
String[] s1 = str1.split("\\.");
System.out.println(s1.length);
for (String s : s1)
{
System.out.println(s);
}
String str2 = "aa|bb|cc|dd|ee";
String[] s2 = str2.split("\\|");
System.out.println(s2.length);
for (String s : s2)
{
System.out.println(s);
}
String str3 = "aa1bb|cc/dd-ee";
String[] s3 = str3.split("1|\\||/|-"); // 可以使用|来隔开多个条件
System.out.println(s3.length);
for (String s : s3)
{
System.out.println(s);
}
String str4 = "aa\\bb\\cc\\dd\\ee";
try
{
String[] s4 = str4.split("\\\\"); // 匹配 \ 此斜杠还真......
System.out.println(str4);
System.out.println("\\\\");
System.out.println(s4.length);
for (String s : s4)
{
System.out.println(s);
}
}
catch (PatternSyntaxException p)
{
System.out.println(p.getDescription());
System.out.println(p.getPattern());
}
}
}
发表评论
- 浏览: 14576 次
- 性别:

- 来自: 成都

- 详细资料
搜索本博客
我的相册
select package lib
共 38 张
共 38 张
最新评论
-
Eclipse中能够减少开发中 ...
写的很精致,请问这些图片是用什么处理的?以及怎么把它们贴上来的?
-- by rmn190 -
Eclipse中能够减少开发中 ...
sb.google.com
-- by 泡 泡 -
SSH2: Struts2 + Spring + ...
楼主,我看了你的配置文件,struts.xml中未指定struts动作由spri ...
-- by sinostone -
SSH2: Struts2 + Spring + ...
nice job,这三个结合,我觉得包最难受,老出错。
-- by xiquwgugou -
SSH2: Struts2 + Spring + ...
不明白你为什么要在Spring中配置Action的Bean,根本没有这个必要的。 ...
-- by jackzhangyunjie






评论排行榜