私は特殊文字~
後とjQueryを使用して文字列の最後の位置にある"fine"
を取得したいこのjQueryで文字列を分割して最後にマッチする方法は?
This is ~test content ~ok ~fine.
のような文字列を持っています。
私は特殊文字~
後とjQueryを使用して文字列の最後の位置にある"fine"
を取得したいこのjQueryで文字列を分割して最後にマッチする方法は?
This is ~test content ~ok ~fine.
のような文字列を持っています。
[substring()] [1]と[lastIndexOf()] [2]の組み合わせを使用して、最後の要素を取得できます。使用することができ
str = "~test content ~thanks ok ~fine";
strFine =str.substring(str.lastIndexOf('~'));
console.log(strFine);
[スプリット()] [4]配列に文字列を変換し、最後のインデックス位置にある要素を取得する配列はゼロベースのインデックスであるように、最後のインデックスはlength of array - 1
あります。
str = "~test content ~thanks ok ~fine";
arr = str.split('~');
strFile = arr[arr.length-1];
console.log(strFile);
OR、単に分割
str = "~test content ~thanks ok ~fine";
console.log(str.split('~').pop());
後単なるJavaScriptを使用してしまった、アレイ上にポップアップを呼び出す:
var str = "This is ~test content ~thanks ok ~fine";
var parts = str.split("~");
var what_you_want = parts.pop();
// or, non-destructive:
var what_you_want = parts[parts.length-1];
ありがとうadil .... – Neel
最初の方法は本当に私のパスで動作していない、ファイル名の最後の "\"を保持..しかし、2番目のスポットです。すごい! – StinkyCat