Android之字符串的拆分-split

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

具体看如下代码:

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

但是要注意的是,如果使用"."、"|"、"^"等字符做分隔符时,要写成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 :

 String s3 = "Real.How.To";
...
temp = s3.split("\\.");
or
String s3 = "Real|How|To";
...
temp = s3.split("\\|");
上一篇:vue+mockjs 模拟数据,实现前后端分离开发


下一篇:soft-nms