您的位置:首页 > 其它

如何按特定字符截取字符串

2007-08-02 10:55 513 查看
例如 ‘ world : 世界’ 按中间的 ‘|’来 分割,得到 ‘world’ 和‘世界’

public class Test {

public static void main(String args[]) {
String ISBN = "world|世界";
int j = 1;
String Left="";
String Right="";
int k= ISBN.length();
for (int i = 0; i < ISBN.length(); i++) {
if (ISBN.substring(i, i + 1).equals("|")) {

Left=ISBN.substring(0,i).trim();
Right=ISBN.substring(i+1,k).trim();

}
else {

}
System.out.println(Left);
System.out.println(Right);

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