当前位置: 首页 >> 程序设计 >> Java >> Java替换字符串的源代码
 

Java替换字符串的源代码

作者:      来源:     发表时间:2006-06-05     浏览次数:      字号:    

 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);
 }
}

责任编辑 webmaster

 
 
 
 
 
评论更多>>
 
 
 
发表
 
姓名: QQ:
性别: MSN:
E-mail: 主页:
评分: 1 2 3 4 5
评论内容:
验证码:
  
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。
  •