Advertisement

算法刷题|字符串——替换连续指定字符串

阅读量:
复制代码
 import java.util.Optional;

    
  
    
 /** * Author:SunLala
    
  * Date: 2022/3/19
    
  * 功能描述:(替换字符串中连续出现的指定字符串)
    
  * 给定三个字符串str,from,to,已知from 子串中无重复字符,把str中所有from的子串全部替换成to字符串,对连续出现的from的部分要求只替换一个to字符,
    
  * 返回最终的结果字符串
    
  */
    
 public class Test6 {
    
     public static void main(String[] args) {
    
 //        System.out.println("123456qwer".regionMatches(2,"aa", 3,  2));
    
     System.out.println(replaceSpecialStr("123abc","abc","4567"));
    
  
    
     }
    
  
    
     public static String replaceSpecialStr(String str, String from,String to) {
    

全部评论 (0)

还没有任何评论哟~