如何使用Java字符串替换方法?
String类的 replace()方法返回一个新字符串,该字符串是用newChar替换此字符串中所有出现的oldChar的结果。
示例
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str = new String("Welcome to Nhooo.com");
System.out.print("返回值:" );
System.out.println(Str.replace('o', 'T'));
System.out.print("返回值:" );
System.out.println(Str.replace('l', 'D'));
}
}输出结果
返回值:WelcTme tT TutTrialspTint.cTm 返回值:WeDcome to TutoriaDspoint.com
热门推荐
10 走心语录简短祝福语
11 新年祝福语给长辈简短
12 66红包祝福语简短的
13 托班祝福语大全简短
14 冬至祝福语简短情话高级
15 苦行老师祝福语结婚简短
16 自己生日祝福语段子简短
17 亲戚结婚祝福语简短大全
18 写给老板祝福语简短高级