javascript - 从 txt 文件中删除字符串
问题描述
所以基本上我想从 txt 文件中删除字符串。
使用 fs
输入示例:
string1
string2
string3
string4
删除string3
删除后会是这样的:
string1
string2
string4
解决方案
读取文本文件获取变量中的内容,然后使用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
推荐阅读
- javascript - 如何用字符串数组过滤对象数组
- javascript - 我无法显示气象图标
- razor-pages - Razor 页面重定向到页面并包含获取信息
- angular - 在守卫中订阅主题不给予回应
- swift - 如何更改 @Published var 会影响另一个 @Published var,例如 Binding
- c# - 有没有办法以管理员身份运行后台工作人员?
- optimization - 定义线性矩阵不等式约束时的 Julia JuMP StackOverflow 错误
- ruby - 在二叉搜索树节点方法中使用 Comparable Mixin
- java - Quarkus REST API with Hibernate/Panache - 端点查询 Postgres 存储过程
- gitversion - GitVersion 会根据 Mainline 模式下的分支以不同方式递增