得到最后的单词js

时间:2013-04-05 01:57:04

标签: javascript jquery words

这删除了最后一个字。我如何得到最后一个字(条纹)?

var BaseShirtURL = "Base Shirt Draped with Fabric Stripe";
BaseShirtURL = BaseShirtURL.substring(0, BaseShirtURL.lastIndexOf(" "));
alert(BaseShirtURL);

2 个答案:

答案 0 :(得分:6)

得到最后一句话:

BaseShirtURL.split(' ').pop();

要删除最后一个字,你可以这样做:

BaseShirtURL = BaseShirtURL.replace(/\w+$/,'');

答案 1 :(得分:1)

这应该这样做:

var BaseShirtURL = "Base Shirt Draped with Fabric Stripe";
var stripe = BaseShirtURL.substring(BaseShirtURL.lastIndexOf(" ") + 1,
    BaseShirtURL.length());
alert(stripe);