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

          與我一起遨游吧

           

          替換字符串的方法

           /**
            * 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)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 阿克苏市| 石家庄市| 根河市| 巫溪县| 中卫市| 浦江县| 林甸县| 盐池县| 隆子县| 茶陵县| 钦州市| 阿拉善盟| 呼玛县| 宣化县| 布拖县| 含山县| 高陵县| 郎溪县| 桃江县| 高平市| 临朐县| 临湘市| 洛浦县| 肃宁县| 葫芦岛市| 曲阜市| 吴川市| 高要市| 揭西县| 新乡县| 云霄县| 安义县| 扎鲁特旗| 河津市| 称多县| 贵定县| 同江市| 新疆| 翁源县| 登封市| 神农架林区|