Dict.CN 在線詞典, 英語學習, 在線翻譯

          都市淘沙者

          荔枝FM Everyone can be host

          統(tǒng)計

          留言簿(23)

          積分與排名

          優(yōu)秀學習網(wǎng)站

          友情連接

          閱讀排行榜

          評論排行榜

          java中split使用簡介

          ?

          java中split使用簡介:

          ------整理:java_流子 Mar.08 2006--------
          java.lang.string.split
          split 方法
          將一個字符串分割為子字符串,然后將結果作為字符串數(shù)組返回。
          stringObj.split([separator,[limit]])
          參數(shù)
          stringObj
          必選項。要被分解的 String 對象或文字。該對象不會被 split 方法修改。
          separator
          可選項。字符串或 正則表達式 對象,它標識了分隔字符串時使用的是一個還是多個字符。如果忽

          略該選項,返回包含整個字符串的單一元素數(shù)組。
          limit
          可選項。該值用來限制返回數(shù)組中的元素個數(shù)。

          說明
          split 方法的結果是一個字符串數(shù)組,在 stingObj 中每個出現(xiàn) separator 的位置都要進行分解

          。separator 不作為任何數(shù)組元素的部分返回。

          示例1:
          public class SplitDemo {
          ?public static String[] ss=new String[20];
          ?public SplitDemo() {
          ??
          ???? String s = "The rain in Spain falls mainly in the plain.";
          ???? // 在每個空格字符處進行分解。
          ???? ss = s.split(" ");?? ??
          ?}?
          ?public static void main(String[] args) {
          ?
          ??SplitDemo demo=new SplitDemo();
          ??for(int i=0;i<ss.length;i++)
          ??System.out.println(ss[i]);
          ?}

          }

          程序結果:
          The
          rain
          in
          Spain
          falls
          mainly
          in
          the
          plain.


          示例2:
          public class SplitDemo {
          ?public static String[] ss=new String[20];
          ?public SplitDemo() {
          ??
          ???? String s = "The rain in Spain falls mainly in the plain.";
          ???? // 在每個空格字符處進行分解。
          ???? ss = s.split(" ",2);????
          ?}?
          ?public static void main(String[] args) {
          ??SplitDemo demo=new SplitDemo();
          ??for(int i=0;i<ss.length;i++)
          ??System.out.println(ss[i]);
          ?}

          }
          程序結果:
          The
          rain in Spain falls mainly in the plain.

          示例3:
          public class SplitDemo {
          ?public static String[] ss=new String[20];
          ?public SplitDemo() {
          ??
          ???? String s = "The rain in Spain falls mainly in the plain.";
          ???? // 在每個空格字符處進行分解。
          ???? ss = s.split(" ",20);????
          ?}?
          ?public static void main(String[] args) {
          ??SplitDemo demo=new SplitDemo();
          ??for(int i=0;i<ss.length;i++)
          ??System.out.println(ss[i]);
          ?}

          }
          程序結果:
          The
          rain
          in
          Spain
          falls
          mainly
          in
          the
          plain.

          posted on 2006-09-07 08:18 都市淘沙者 閱讀(3088) 評論(0)  編輯  收藏 所屬分類: Java Basic/Lucene/開源資料

          主站蜘蛛池模板: 新源县| 西充县| 镇康县| 东台市| 法库县| 瓦房店市| 浦北县| 武夷山市| 宜兰市| 武安市| 秭归县| 黄骅市| 平湖市| 连州市| 佛教| 威宁| 潞城市| 顺平县| 怀来县| 军事| 贡嘎县| 汉中市| 九龙城区| 合阳县| 昂仁县| 太康县| 迁西县| 蒙自县| 田阳县| 龙泉市| 巫溪县| 南召县| 台湾省| 松阳县| 景洪市| 额尔古纳市| 铁岭县| 河池市| 陵水| 高阳县| 北海市|