vb.net - 在VB .Net中的子字符串之前修剪字符串
问题描述
我正在尝试找到一种在子字符串之前修剪字符串的方法,即只返回字符串的左侧。
前:
[REMOVE] = 1 (Line0)
G77 H9002 (Line1)
[ZAXIS] = 25 (Line2)
后:
[REMOVE] = 1
G77 H9002
[ZAXIS] = 25
我想修剪“(行”子字符串之前的字符串(也删除右侧剩余的所有字符)。在 VBA 中这很容易实现,但在 VB .Net 中它不是那么简单。请指导我一个可能的解决方案? 谢谢
解决方案
Dim strs = File.ReadLines("c:\\SomeFile.txt") 'Read the file
Using sw = File.CreateText("c:\Target") 'File to save to
For Each str In strs
Dim i = str.LastIndexOf("(Line") 'Find the index to cut
Dim newStr = str.Substring(0, i) 'Cut the line at index
sw.WriteLine(newStr) 'Write new string to new file.
Next
End Using
推荐阅读
- tensorflow - Tensorflow - 即使形状看起来没问题,在 feed_dict() 上也会出现形状错误
- java - Presto SocketTimeoutException
- velocity.js - 速度js汉堡菜单功能
- javascript - 未处理的拒绝(错误):给定的操作返回未定义的 React JS
- user-interface - 当前可见的视口部分是否有官方术语?
- firebase - 单个属性上的 NeedIndexError (Google AppEngine + Firestore)
- c# - 找不到没有返回所有用户的 PeopleManager 和 SiteUserInfoList
- dataframe - Octave - 数据框列名?
- python - pandas:创建一个从 1 到每组长度的列
- c# - 我可以用 IEnumerable 写这个 lambda
而不是 IEnumerable ?