Extract second Line from a text Using JavaScript

Viewed 21

I need to extract the second line of a text and I have a hard time finding sources where I use JavaScript. My following code is design to get extract the information in the same line.

Text Example:

Name: John Smith 

Are you a current customer? 
Yes

Code:

         if(pmsg.indexOf ("Name: ")>0) {
           var end = pmsg.substring(pmsg.indexOf("Name:")+6,pmsg.length);
           name = end.substring(0, end.indexOf("\n"));
          }
         if(pmsg.indexOf("Are you a current customer? ")>0) {
           var end = pmsg.substring(pmsg.indexOf("Are you a current customer? ")+28,pmsg.length);


Desired Output:

John Smith
No

I have done some research and I think I need to use the ReadLine method? I can extract the name just fine because "Name: " it is in the same line and and I can just say retrieve everything after Name: but it is difficult for me to retrieve the next line of code.

1 Answers

I cant figure how you get the email, but you can split the whole string with

email.split(/\r\n|\n/); and save it to an array this would get every line as a different position of the array

hope it works

Related