【转】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 on 2012-08-12 14:23  Code大蛇丸  阅读(975)  评论(0编辑  收藏  举报