用基本字串中的替換字串替換與目標字串匹配的所有匹配項。
替換從字串的開頭到結尾,例如,在字串"aaa"中將"aa"替換為"b"將導致"ba"而不是"ab"。
字串
replaceAll(<parameters>)
參數 | 類型 |
---|---|
基礎 | 字串 |
Target | 字串(RegExp) |
替換 | 字串 |
replaceAll(<baseString>,<sourceString>,<replacementString>)
返回字串。
replaceAll("Hello World", "l", "x")
返回"Hexxo Worxd"。
由於目標參數是RegExp,因此您可能需要轉義一些字元,具體取決於要替換的字串。 請參閱中的示例 此頁。