函数原型为String replace(String str,String old,String with),str为被截取的字符串,old为str的子串,with用来替代old子串:
要求是假如with含有'*'字符,则'*'可以代替str中的任意一个字符,如果这样的'*'有多个,并且与字符交替出现等等情况呢?
例:str = "csdnjavase" old = "d*j" with = "help"
输出"cshelpavase"
请大家给给点子!

解决方案 »

  1.   

    没怎么看懂,这个能用不?public static void main(String[] args) throws IOException {
    System.out.println(replace("csdnjavase", "d*j", "help"));
    System.out.println(replace("csdnjavase", "d***v", "help"));
    } private static String replace(String str, String old, String with){
    old = old.replaceAll("\\*", ".");
    return str.replaceAll(old, with);
    }
      

  2.   

    不是纯粹的替换,还得看看old是不是str的子串,即使是old包含'*'!