我有以下内容:
var S="hi how are you";
var bindex = 2;
var eindex = 6;
Run Code Online (Sandbox Code Playgroud)
我如何从存在于bindex和eindex之间的S中删除所有字符?
因此S将是"你好,你是谁"
小智 36
在bindex之前获取文本并在eindex之后与文本连接,如:
var S="hi how are you";
var bindex = 2; var eindex = 6;
S = S.substr(0, bindex) + S.substr(eindex);
Run Code Online (Sandbox Code Playgroud)
S现在是"你好吗"
Anu*_*rag 16
首先找到要替换的字符串的子字符串,然后用空字符串替换该字符串的第一个匹配项.
S = S.replace(S.substring(bindex, eindex), "");
Run Code Online (Sandbox Code Playgroud)
另一种方法是将字符串转换为数组,splice输出不需要的部分并再次转换为字符串.
var result = S.split('');
result.splice(bindex, eindex - bindex);
S = result.join('');
Run Code Online (Sandbox Code Playgroud)
Ale*_*rar 11
尝试
S = S.substring(0, bindex)+S.substring(eindex);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25534 次 |
| 最近记录: |