Hca*_*tek 3 javascript string parsing substring
我有一个字符串"2500 - SomeValue".如何删除'SomeValue'中'S'之前的所有内容?
var x = "2500 - SomeValue";
var y = x.substring(x.lastIndexOf(" - "),
// this is where I'm stuck, I need the rest of the string starting from here.
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
〜CK
将3(长度" - ")添加到最后一个索引,并取消第二个参数.将一个参数传递给substring时的默认值是转到字符串的末尾
var y = x.substring(x.lastIndexOf(" - ") + 3);
Run Code Online (Sandbox Code Playgroud)