目前未提供另外两个选项,第一个是使用indexOf()
:
var cookie = "__utma=43024181.64497201.1349454717.1349695569.1349702850.4;__utmz=43024181.1349679955.2.2.utmcsr=aerosoft-press.com|utmccn=referral)|utmcmd=referral|utmcct=/;__utmc=43024181; __utmb=43024181.8.10.1349702850; language=de",
newCookie = cookie.substring(0,cookie.indexOf(' language'));
console.log(newCookie);
JS 小提琴演示。
第二种用途lastIndexOf()
:
var cookie = "__utma=43024181.64497201.1349454717.1349695569.1349702850.4;__utmz=43024181.1349679955.2.2.utmcsr=aerosoft-press.com|utmccn=referral)|utmcmd=referral|utmcct=/;__utmc=43024181; __utmb=43024181.8.10.1349702850; language=de",
// the '+ 1' in the following line assumes you want to keep the ';' character
newCookie = cookie.substring(0,cookie.lastIndexOf(';') + 1);
console.log(newCookie);
JS 小提琴演示。
参考: