![見出し画像](https://assets.st-note.com/production/uploads/images/11356100/rectangle_large_type_2_59366b5c795d5e66334bffed8a1f04e9.jpeg?width=1200)
Photo by
lazy_planet
GAS|文字列の後方一致を判定する|endsWith|Javascript|Google Apps Script|開発裏話
「マンガポスト日本版」の実装に必要だったのですが、GAS には「endsWith」がありませんでした。
文字列の後方一致を判定したい場合、以下のように、自分でメソッドを作っておくと便利です。
/**
* Whether a string ends with the characters of a specified string.
*
* @param string — a string
* @param searchString — the string to search for
* @return Boolean — returns true if the string ends with the value, otherwise it returns false
*/
function endsWith(string, searchString) {
return (((string.lastIndexOf(searchString) + searchString.length) === string.length) && (searchString.length <= string.length));
}
マンガポスト日本版
マンガポスト日本版の Twitter 公式アカウントです。
漫画(まんが)・コミックの新刊情報を毎日配信中!
コーヒーブレイク
連邦軍人として新たな活動を始めていたシャアは、新型ガンダム強奪をきっかけにニュータイプの少年カミーユと遭遇する。その二人の出会いが、エゥーゴとティターンズの戦いに火を点けることに…。