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

          與我一起遨游吧

           

          替換字符串的方法

           /**
            * 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 閱讀(165) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 信宜市| 土默特右旗| 沂源县| 中宁县| 道孚县| 易门县| 永春县| 凤山县| 洪洞县| 江西省| 监利县| 永年县| 天等县| 英吉沙县| 屏边| 含山县| 张家港市| 吉水县| 平阳县| 宝山区| 包头市| 饶河县| 延吉市| 化州市| 林甸县| 偏关县| 介休市| 惠来县| 榆树市| 宝坻区| 珠海市| 新巴尔虎左旗| 洛宁县| 泊头市| 炎陵县| 镇巴县| 延寿县| 田阳县| 察雅县| 苗栗县| 乌兰察布市|