摘要 腾兴网为您分享:java replace字符替换函数,作业大师,找乐助手,小学英语,趣趣英语等软件知识,以及保险师,u盘写保护,天正2014,rwallpaper,mp4,文通鼠标手写输入法,连客,tts语音合成,生命绿洲,小黄鸭头像,ftp软件,凤凰系统,minilyrics,主管护师题库,邦融汇等软件it资讯,欢迎关注腾兴网。public String replace(char oldChar,char newChar) 返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 得到的。 如果 oldChar 在此 String 对象表示的字符序列中没有出现,则返回...
public String replace(char oldChar, char newChar)
返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 得到的。
如果 oldChar 在此 String 对象表示的字符序列中没有出现,则返回对此 String 对象的引用。
否则,创建一个新的 String 对象,它所表示的字符序列除了所有的 oldChar 都被替换为 newChar 之外,与此 String 对象表示的字符序列相同
public class MainClass
{
public static void main( String args[] )
{
String s1 = new String( "hello" );
String s2 = new String( "GOODBYE" );
String s3 = new String( " spaces " );
System.out.printf( "s1 = %sns2 = %sns3 = %snn", s1, s2, s3 );
// test method replace
System.out.printf("Replace 'l' with 'L' in s1: %snn", s1.replace( 'l', 'L' ) );
} // end main
}
对于特殊nr我们把它替换成br
public class Main {
public static void main(String[] argv) {
System.out.println("rn|r|n|nr".replaceAll("(rn|r|n|nr)", "
"));}
}
//
|
|
|
相关推荐