但是需要注意的是,
str = "this is string example....wow!!! this is really string";
print str.replace("is", "was");
print str.replace("is", "was", 3);
输出的结果:
thwas was string example....wow!!! thwas was really string thwas was string example....wow!!! thwas is really string
这个里面把所有含有要替换的字符的都给替换掉了,后面的数字,就是替换几个,一般应该是从左往右进行的
如果只想替换单独的“is”,也就是this里面的is不替换的话。那么可以自己从新用字符串拼接一下,比如“this‘+' '+'is'+...等等去重新构造,简单的str.replace()并不能完成这个指定的精准操作。