Uso
substring
funzione
restituisce un sottoinsieme di una stringa tra un indice e l'altro, o attraverso il fine della stringa.
substring(indexA, [indexB]);
INDEXA
An integer between 0 and one less than the length of the string.
indiceB, specificati (facoltativo) Un numero intero tra 0 e la lunghezza della stringa.
La sottostringa estrae caratteri dall'indiceA fino a ma non incluso l'indiceB. In particolare:
* If indexA equals indexB, substring returns an empty string.
* If indexB is omitted, substring extracts characters to the end
of the string.
* If either argument is less than 0 or is NaN, it is treated as if
it were 0.
* If either argument is greater than stringName.length, it is treated as
if it were stringName.length.
Se INDEXA è maggiore di indiceB, specificati, allora l'effetto di stringa è come se sono stati scambiati i due argomenti; ad esempio, str.substring (1, 0) == str.substring (0, 1).
Solo per curiosità ... lo String.substr() il metodo sembra funzionare per la maggior parte degli scenari che incontro - ma ti sembra di avere la necessità di rimuovere un "middle" bit stringa - hai un assaggiare il caso del "mondo reale" in cui ciò avviene regolarmente? – scunliffe
Perché non dovresti tagliare 0-2 e 5-6? – dlamblin