替換字符串

           public class StyleSearchAndReplace {
           public static void main(String args[]) {

             String statement = "The question as to whether the jab is"
                 + " superior to the cross has been debated for some time in"
                 + " boxing circles. However, it is my opinion that this"
                 + " false dichotomy misses the point. I call your attention"
                 + " to the fact that the best boxers often use a combination of"
                 + " the two. I call your attention to the fact that Mohammed"
                 + " Ali,the Greatest of the sport of boxing, used both. He had"
                 + " a tremendous jab, yet used his cross effectively, often,"
                 + " and well";

             String newStmt = statement.replaceAll("The question as to whether",
                 "Whether");

             newStmt = newStmt.replaceAll(" of the sport of boxing", "");
             newStmt = newStmt.replaceAll("amount of success", "success");
             newStmt = newStmt.replaceAll("However, it is my opinion that this",
                 "This");

             newStmt = newStmt.replaceAll("a combination of the two", "both");
             newStmt = newStmt.replaceAll("This is in spite of the fact that"
                 + " the", "The");
             newStmt = newStmt.replaceAll("I call your attention to the fact that",
                 "");

             System.out.println("BEFORE:\n" + statement + "\n");
             System.out.println("AFTER:\n" + newStmt);
           }
          }

          posted on 2007-06-26 16:01 付軒 閱讀(259) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          <2007年6月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(2)

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 北流市| 孝昌县| 肇庆市| 洛川县| 柘荣县| 东阿县| 伽师县| 云林县| 兰州市| 宝兴县| 潮安县| 宜阳县| 阿拉善右旗| 静安区| 南华县| 长汀县| 大同市| 麻城市| 桃园市| 淮南市| 贵定县| 沙河市| 郁南县| 墨脱县| 阜城县| 甘南县| 灌阳县| 曲水县| 西藏| 石景山区| 建德市| 连城县| 镇平县| 七台河市| 黎川县| 五台县| 临城县| 灵台县| 宜春市| 松江区| 琼结县|