I have a string with multiple commas, and the string replace method will only change the first one:
(我有一个带有多个逗号的字符串,字符串替换方法只会更改第一个:)
var mystring = "this,is,a,test"
mystring.replace(",","newchar", -1)
Result : "thisnewcharis,a,test"
(结果 : "thisnewcharis,a,test"
)
The documentation indicates that the default replaces all, and that "-1" also indicates to replace all, but it is unsuccessful.
(该文档指示默认值将替换所有,而“ -1”也指示将替换所有,但未成功。)
Any thoughts? (有什么想法吗?)
ask by mike translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…