Uso
substring
función
Devuelve un subconjunto de una cadena entre un índice y otro, o hasta el final de la cadena .
substring(indexA, [indexB]);
indiceA
An integer between 0 and one less than the length of the string.
indiceB (opcional) Un entero entre 0 y la longitud de la cadena.
subcadena extrae los caracteres de indexA hasta pero no incluye indexB. En particular:
* 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.
Si indiceA es mayor que indiceB, entonces el efecto de subcadena es como si se intercambian los dos argumentos; por ejemplo, str.substring (1, 0) == str.substring (0, 1).
Sólo por curiosidad ... el String.substr() método parece funcionar para la mayoría de los escenarios que encuentro - sin embargo, parecen tener una necesidad de quitar un poco cadena "media" - ¿tiene una muestra del caso del "mundo real" donde esto ocurre regularmente? – scunliffe
¿Por qué no cortaría 0-2 y 5-6 en su lugar? – dlamblin