vb.net - 仅删除文本文档上的某些内容 (VB.NET 4.8)
问题描述
我的问题看起来很复杂,但并不是那么复杂。我有一个文本文档,其中包含:
消除
消除
消除
消除
保持
保持
等等。为 KEEP
我想只删除 REMOVE 并保持 KEEP 没有空间。怎么做?
谢谢!
解决方案
在代码文件的顶部...
Imports System.IO
然后我们可以使用File
这个命名空间中的类。请参阅https://docs.microsoft.com/en-us/dotnet/api/system.io.file?view=netcore-3.1
Private Sub RemoveRemove()
Dim lines = File.ReadAllLines("C:\Users\maryo\Desktop\KeepRemove.txt")
Dim KeepLines As New List(Of String)
For Each line In lines
If line.StartsWith("KEEP") Then
KeepLines.Add(line)
End If
Next
File.WriteAllText("C:\Users\maryo\Desktop\Keep.txt", String.Join(vbCrLf, KeepLines))
End Sub
推荐阅读
- c# - 以 pdf 格式发送 html 视图并在 mvc 中发送电子邮件
- c - 我的代码有什么错误吗?我是新手
- java - Spring kafka @KafkaListener 未被调用
- reactjs - 在 reactjs 中创建多选时出错
- node.js - 像这样从带有 JSON 格式的数据的 Parsed JSON 中提取?
- netsuite - Netsuite 2.0 搜索来自 WEB 商店的 SalesOrders 过滤器
- excel - 需要请求令牌、授权和访问令牌的 VBA API GET
- typo3 - 为什么 Extbase PersistenceManager 认为我的对象是新的?
- r - 如何从自定义环境中获取所有数据框对象
- unity3d - 如何从另一个脚本调用协程?