Java replace() 方法 替换字符 也可用于 js 中

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"




 

posted @ 2019-11-19 17:13  _情书  阅读(725)  评论(0编辑  收藏  举报