Android之字符串的拆分-split

 

字符串的拆分可以利用android的 split 来简单实现

具体看如下代码:

1     String s3 = "Real-How-To";  
2     String [] temp = null;  
3     temp = s3.split("-");  
4     etShow.setText(temp[0] + " linc " + temp[1]); 

 

但是要注意的是,如果使用"."、"|"、"^"等字符做分隔符时,要写成s3.split("\\^")的格式,

否则不能拆分。

 

参见http://www.rgagnon.com/javadetails/java-0438.html

split() is based on regex expression, a special attention is needed with some characters which have a special meaning in a regex expression.

For example :

1 String s3 = "Real.How.To";  
2 ...  
3 temp = s3.split("\\.");  
4 or  
5 String s3 = "Real|How|To";  
6 ...  
7 temp = s3.split("\\|"); 

 

posted @ 2016-03-22 15:14  UniqueColor  阅读(1972)  评论(0编辑  收藏  举报