首页 > 技术文章 > Java replace() 方法 替换字符 也可用于 js 中

yydxh 2019-11-19 17:13 原文

JAVA中:

public class Test { public static
void main(String args[]) { String Str = new String("hello"); System.out.print("返回值 :" ); System.out.println(Str.replace('o', 'T')); System.out.print("返回值 :" ); System.out.println(Str.replace('l', 'D')); } } 返回值 :hellT 返回值 :heDDo


JS中:
  var Str = "hello"
  Str.
replace('o','T'); 返回:Str = "hellT"
  Str.replace('l','D'); 返回:Str = "heDDo"




 

推荐阅读