1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
//js 截取指定字符后面/前面的所有字符串
let str = '你还好吗?嗯?我很好!'
//截取第一个?前面的字符串
var index = str.indexOf("?")
var resolve = str.substring(0, index);
console.log(resolve)
//你还好吗
//截取第一个?后面的字符串
var indexs = str.indexOf("?")
var resolves = str.substring(indexs + 1, str.length);
console.log(resolves)
//嗯?我很好!
//截取最后一个?前面的字符串
let indexss = str.lastIndexOf("?")
var resolvess = str.substring(0, indexss);
console.log(resolvess)
//你还好吗?嗯
//截取最后一个?后面的字符串
let indexsss = str.lastIndexOf("?")
var resolvesss = str.substring(indexsss + 1, str.length);
console.log(resolvesss)
//我很好! |
//js 截取指定字符后面/前面的所有字符串
let str = '你还好吗?嗯?我很好!'
//截取第一个?前面的字符串
var index = str.indexOf("?")
var resolve = str.substring(0, index);
console.log(resolve)
//你还好吗
//截取第一个?后面的字符串
var indexs = str.indexOf("?")
var resolves = str.substring(indexs + 1, str.length);
console.log(resolves)
//嗯?我很好!
//截取最后一个?前面的字符串
let indexss = str.lastIndexOf("?")
var resolvess = str.substring(0, indexss);
console.log(resolvess)
//你还好吗?嗯
//截取最后一个?后面的字符串
let indexsss = str.lastIndexOf("?")
var resolvesss = str.substring(indexsss + 1, str.length);
console.log(resolvesss)
//我很好!