How to get the first line of a multi-line string in TypeScript

1 Answer

0 votes
const multiLineString: string = 
        "First line\n" +
        "Second line\n" +
        "Third line\n" +
        "Fourth line\n" + 
        "Fifth line";
         
const firstLine: string = multiLineString.substring(0, multiLineString.indexOf("\n"));
         
console.log("The first line is: " + firstLine);
 
 
  
/*
run
 
"The first line is: First line" 
  
*/


 



answered Aug 13, 2024 by avibootz

Related questions

1 answer 215 views
1 answer 209 views
1 answer 196 views
1 answer 210 views
1 answer 206 views
1 answer 215 views
2 answers 241 views
...