YuFeng

java 正则之replace和replaceAll方法简介
/* replace 是对相应的字符串替换... */ public static void main(Strin...
扫描右侧二维码阅读全文
25
2018/06

java 正则之replace和replaceAll方法简介

/*
replace 是对相应的字符串替换...
*/
public static void main(String[] args) {
        String count = "abcdefga";
        String regex = "a";
        count = count.replace(regex,"*");
        System.out.println(count);
    }
/*
运行结果为:*bcdefg*
*/


/*
replaceAll 所接受的是相应的正则表达式
*/
String count = "abcdefga";
        String regex = ".";   //任意字符
        count = count.replaceAll(regex,"*");
        System.out.println(count);
/*
运行结果为:********
*/
Last modification:June 25th, 2018 at 01:10 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment