February 17,2006

indexof 找出string 的長度

直接利用 String 類別的method -> split , 把原始字串切割成字串陣列就可以了
測試程式如下:
public class StringSplitTest {
public static void main(String[] args) {
String str = "abc , def ,ghi";
String strE[]=str.split(",");
for (int i=0;i System.out.println(strE[i]);
}
}
}
//以下是執行結果
abc
def
ghi


Posted by yam_javanull at 樂多Roodo! │10:52 │回應(3)引用(0)Java
樂多分類:網路/3C 共同主題:程式設計 工具:編輯本文
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/1134247
回應文章
String str = "abc , def ,ghi";
int i=-1;
while(true){

i = str.indexOf(",", i+1);

if(i > -1)
System.out.println(i) ; // 算出所有 indexof(",") 的長度位置
else
break;

}
Posted by java at March 5,2006 23:45
public class StringSplitTest {
public static void main(String[] args) {
String str = "abc , def ,ghi";
String strE[]=str.split(",");
for (int i=0;i
Posted by java at March 5,2006 23:52
Posted by javanull at April 6,2006 11:34