這將刪除最後一個單詞。我如何得到最後一個詞(條紋)?獲取最後一個單詞js
var BaseShirtURL = "Base Shirt Draped with Fabric Stripe";
BaseShirtURL = BaseShirtURL.substring(0, BaseShirtURL.lastIndexOf(" "));
alert(BaseShirtURL);
這將刪除最後一個單詞。我如何得到最後一個詞(條紋)?獲取最後一個單詞js
var BaseShirtURL = "Base Shirt Draped with Fabric Stripe";
BaseShirtURL = BaseShirtURL.substring(0, BaseShirtURL.lastIndexOf(" "));
alert(BaseShirtURL);
要獲得最後一個字:
,並刪除最後一個字,你可以這樣做:
BaseShirtURL = BaseShirtURL.replace(/\w+$/,'');
我測試過在其他答案中描述的分割vs切片方法,並且對於500萬次旋轉,分割速度更快。圖(毫秒):http://i.imgur.com/C6rvuCp.png測試來源:http://jsfiddle.net/4k3cf/ – Tomas 2014-02-20 16:23:33
這應做到:
var BaseShirtURL = "Base Shirt Draped with Fabric Stripe";
var stripe = BaseShirtURL.substring(BaseShirtURL.lastIndexOf(" ") + 1,
BaseShirtURL.length());
alert(stripe);
' BaseShirtURL = BaseShirtURL.substring(BaseShirtURL.lastIndexOf(「」),BaseShirtURL.le ngth);' – 2013-04-05 01:58:48
這是一個不同的方法http://stackoverflow.com/a/5673858/1011213 – codeqi 2013-04-05 02:03:33
這是有幫助的。它如何被本地化? – twiz 2013-06-10 01:19:16