I wrote a script for some text manipulation, and want to add a function so that the first line of my input string is removed if it starts with the symbol ‘>’. I tried to find a solution for hours now, but I cannot get it to work: Somehow the first line is not removed properly.
My input text should be processed as it is if it looks like this:
“HABHHIKKLLMMNMNIL”
and the first line should be removed if it looks like this:
“
>some text
HABHHIKKLLMMNMNIL
“
My current solution would look like this:
// remove first line if starts with '>'
if (sequence_str.substring(0) === '>'){
// break the textblock into an array of lines
var lines = sequence_str.split('\n');
// remove one line, starting at the first position
lines.splice(0,1);
// join the array back into a single string
var sequence_str = lines.join('\n');
}
sequence_str = sequence_str.replace(/(\r\n|\n|\r)/gm,""); //remove linebreaks
I would appreciate any ideas, and I hope some could help me to figure out where the problem is.
Thanks!
Why not just this?
This will remove the first line if it starts with
>. It will leave an empty line (the newline character is unaffected), but since you’re later stripping all line-breaks, it doesn’t matter.