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

          與我一起遨游吧

           

          替換字符串的方法

           /**
            * 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) 評論(0)  編輯  收藏


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


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

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 长海县| 石林| 仙游县| 聂拉木县| 扶风县| 堆龙德庆县| 五大连池市| 庐江县| 静宁县| 绥中县| 金山区| 如东县| 本溪市| 民和| 江城| 盐源县| 柯坪县| 读书| 安多县| 马关县| 冕宁县| 巢湖市| 康马县| 浦县| 五大连池市| 萨嘎县| 侯马市| 亚东县| 河北区| 格尔木市| 彭州市| 娄烦县| 鄂州市| 福建省| 巴中市| 泸溪县| 静乐县| 宿迁市| 星子县| 仙游县| 江西省|