javascript - Remove one line in txt file ( NODE.js) -
i make text file "foo\nbar\nbas"
when append coke(with adding \n), file "foo\nbar\nbas\ncoke"
i want remove foo.
help me!
fo use case have provided, simple answer split on \n, remove first item, add new item end, , join array form new string.
var parts = "foo\nbar\nbas".split("\n").slice(1); parts.push("coke"); var updated = parts.join("\n");
other option use indexof find first occurrence of \n
, substring select portion of string, simple concatenation.
var str = "foo\nbar\nbas"; var position = str.indexof("\n")+1; var updated = str.substring(position) + "\ncoke";
Comments
Post a Comment