Java String replace()方法示例。
String类的replace()方法接受两个参数,即-
oldChar-旧字符。
newChar-新字符。
返回一个新的String,该字符串是用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 身体康复的祝福语简短
13 看病贺卡祝福语简短英文
14 给叔叔虎年祝福语简短
15 新婚过年祝福语大全简短
16 高考祝福语简短10字
17 生日祝福语 简短独特高考
18 口才课期末祝福语简短