我为一些文本操作编写了一个脚本,并想添加一个函数,以便删除以符号“>”开头的输入字符串的第一行。我试图找到一个解决方案几个小时,但我无法让它工作:不知何故第一行没有正确删除。
我的输入文本应该按原样处理,如果它看起来像这样:“ HABHHIKKLLMMNMNIL
”,如果它看起来像这样,则应该删除第一行:“
>some text
HABHHIKKLLMMNMNIL
"
我当前的解决方案如下所示:
// 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
我会很感激任何想法,我希望有些想法可以帮助我找出问题所在。
谢谢!