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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -