我的空間,寫我所寫,禪我所藏

          與我一起遨游吧

           

          替換字符串的方法

           /**
            * Replace all occurence of forReplace with replaceWith in input string.
            *
            * @param input
            *            represents input string
            * @param forReplace
            *            represents substring for replace
            * @param replaceWith
            *            represents replaced string value
            * @return new string with replaced values
            */
           private static String replaceAll(String input, String forReplace,
             String replaceWith) {
            if (input == null)
             return null;
            StringBuffer result = new StringBuffer();
            boolean hasMore = true;
            while (hasMore) {
             int start = input.indexOf(forReplace);
             int end = start + forReplace.length();
             if (start != -1) {
              result.append(input.substring(0, start) + replaceWith);
              input = input.substring(end);
             } else {
              hasMore = false;
              result.append(input);
             }
            }
            if (result.toString().equals(""))
             return input; // nothing is changed
            else
             return result.toString();
           }

          posted on 2007-06-25 10:59 imcb 閱讀(162) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 县级市| 平利县| 宁陵县| 鹤壁市| 南木林县| 金溪县| 大洼县| 项城市| 长泰县| 永嘉县| 赞皇县| 施甸县| 商水县| 繁峙县| 铜梁县| 阿鲁科尔沁旗| 武川县| 富源县| 尤溪县| 喜德县| 永春县| 璧山县| 临城县| 合肥市| 贡嘎县| 湾仔区| 陈巴尔虎旗| 岑溪市| 昌宁县| 时尚| 正定县| 高清| 台北县| 宽甸| 广南县| 信阳市| 赣榆县| 屏东市| 梁平县| 根河市| 玛曲县|