0
可以說我們必須使用Substring()和/或Substr()或兩個字符串方法來對字符串var first = "hi my name is this";
和var second = "this";
進行處理,我想檢查第二個字符串是否匹配首先結束(我知道String.prototype.endsWith())。這怎麼能做到?感謝使用Substring()和Substr()來處理兩個字符串並且Substr()
到目前爲止,我有這個,但它的錯誤
function confirmEnding(str, target) {
// calculate the length of second string
// remove the end of the first string (same amount) with the first string
//compare the two
var secondStringLen = target.length;
var firstStringLen = str.length;
var firstStringEnding = str.substring(secondStringLen+1, -1);
return firstStringEnding;
}
confirmEnding("abcaqwexefg", "efg");
'如果first.split(」「).pop()==秒' – AshBringer
@ T.J.Crowder我更新了我的問題。並且在網上找不到類似的問題 – dadadodo
簡單如這個'if(first.endsWith(second))'! – Pugazh