Ho stringa come questaCome dividere una stringa e ottenere l'ultima corrispondenza in jQuery?
This is ~test content ~ok ~fine.
voglio arrivare "fine"
che è dopo carattere speciale ~
e ultima posizione nella stringa utilizzando jQuery.
Ho stringa come questaCome dividere una stringa e ottenere l'ultima corrispondenza in jQuery?
This is ~test content ~ok ~fine.
voglio arrivare "fine"
che è dopo carattere speciale ~
e ultima posizione nella stringa utilizzando jQuery.
È possibile utilizzare la combinazione di [sottostringa()] [1] e [lastIndexOf()] [2] per ottenere l'ultimo elemento.
str = "~test content ~thanks ok ~fine";
strFine =str.substring(str.lastIndexOf('~'));
console.log(strFine);
È possibile usare [split()] [4] per convertire la stringa di matrice e ottenere l'elemento in ultimo indice, ultimo indice è length of array - 1
come matrice è indice di base zero .
str = "~test content ~thanks ok ~fine";
arr = str.split('~');
strFile = arr[arr.length-1];
console.log(strFile);
O, semplicemente chiamare pop di matrice ottenuto dopo la divisione
str = "~test content ~thanks ok ~fine";
console.log(str.split('~').pop());
Basta usare pianura 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];
Grazie adil .... – Neel
il primo metodo non funziona davvero con il mio percorso, mantiene l'ultima "\" nel nome del file .. ma il secondo è azzeccato. thks! – StinkyCat