Tengo un área de texto que debo analizar. Cada nueva línea necesita ser extraída y se debe realizar una operación en ella. Después de que la operación finaliza, la operación debe ejecutarse en la siguiente línea. Esto es lo que tengo en este momento. Sé que la búsqueda de indexOf no funcionará porque está buscando carácter por carácter.analizar un área de texto en subcadenas basadas en saltos de línea en Javascript
function convertLines()
{
trueinput = document.getElementById(8).value; //get users input
length = trueinput.length; //getting the length of the user input
newinput=trueinput; //I know this looks silly but I'm using all of this later
userinput=newinput;
multiplelines=false; //this is a check to see if I should use the if statement later
for (var i = 0; i < length; i++) //loop threw each char in user input
{
teste=newinput.charAt(i); //gets the char at position i
if (teste.indexOf("<br />") != -1) //checks if the char is the same
{
//line break is found parse it out and run operation on it
userinput = newinput.substring(0,i+1);
submitinput(userinput);
newinput=newinput.substring(i+1);
multiplelines=true;
}
}
if (multiplelines==false)
submitinput(userinput);
}
Por lo tanto, en su mayor parte está tomando la entrada del usuario. Si tiene líneas multiples se ejecutará lanzando cada línea y por separado y ejecutar submitinput. Si ustedes pueden ayudarme, estaré eternamente agradecido. Si tiene alguna pregunta por favor pregunte