方法 | 描述 |
---|---|
String[] split(String regex) String[] split(String regex, int limit) | 將原字串利用 regex 拆開存入字串陣列,然後回傳這個字串陣列 |
舉例如下
class SplitDemo { public static void main(String[] args) { String a = "Imagination is more important than knowledge."; String b = "He who has hope has everything."; String c = "台上一分鐘,台下十年功。"; String[] aArray = a.split(" "); String[] bArray = b.split(" ", 2); String[] cArray = c.split(","); for (String d : aArray) { System.out.println(d); } for (String d : bArray) { System.out.println(d); } for (String d : cArray) { System.out.println(d); } } } /* 《程式語言教學誌》的範例程式 http://pydoing.blogspot.com/ 檔名:SplitDemo.java 功能:示範物件導向的基本觀念 作者:張凱慶 時間:西元 2010 年 10 月 */
編譯後執行,結果如下
中英文術語對照 | |
---|---|
類別 | class |
方法 | method |
字串 | string |
陣列 | array |
參考資料
http://download.oracle.com/javase/tutorial/java/data/strings.html
http://download.oracle.com/javase/tutorial/java/data/converting.html
http://download.oracle.com/javase/tutorial/java/data/manipstrings.html
http://download.oracle.com/javase/tutorial/java/data/comparestrings.html
http://download.oracle.com/javase/7/docs/api/java/lang/String.html
http://download.oracle.com/javase/tutorial/java/data/strings.html
http://download.oracle.com/javase/tutorial/java/data/converting.html
http://download.oracle.com/javase/tutorial/java/data/manipstrings.html
http://download.oracle.com/javase/tutorial/java/data/comparestrings.html
http://download.oracle.com/javase/7/docs/api/java/lang/String.html
2 則留言:
很簡單易懂 謝謝
讚,謝謝
張貼留言