首页 > 解决方案 > 从 txt 文件中删除字符串

问题描述

所以基本上我想从 txt 文件中删除字符串。

使用 fs

输入示例:

string1
string2
string3
string4

删除string3

删除后会是这样的:

string1
string2
string4

标签: javascriptnode.jsfs

解决方案


读取文本文件获取变量中的内容,然后使用String.replace

例如

var stringContent="Here goes the content of the textFile after read"
 var res=stringContent.replace('string3','');
//write back res to the file or do what ever

推荐阅读