2010年12月10日 星期五

分割字串 ( spilt )

轉貼連結




使用分隔字元切割字串 spilt()方法,這是 J2SE 1.4新增的方法


class s038
{
public static void main(String args[])
{
String str = "基隆,台北,桃園,新竹,苗栗,台中,彰化,雲林,嘉義,台南,高雄";
System.out.println(" 字串 = "+str);
String[] token = str.split(",");


for (int i=0; i {System.out.println(" token[ "+i+" ] = "+token[i]);}


} //end of main
} // end of class

沒有留言:

張貼留言