有没有高效获取关键字符所在行的内容。

余温生 2018-07-01 12:36:40
比如文本txt:
12345678
88888888
87635655
26793455
7777777777

结果,获取包含字符8的行:
12345678
88888888
87635655


用Split发现运行很卡,请教各位大神高效的方法。
...全文
699 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
melinyi 2018-07-14
  • 打赏
  • 举报
回复
这个是VB的示例 https://zhidao.baidu.com/question/1575416082789160900.html
raynors 2018-07-14
  • 打赏
  • 举报
回复
搞啥,直接INSTR()

还用得着正则式?
zj_zwl 2018-07-04
  • 打赏
  • 举报
回复


Imports System.Text.RegularExpressions

Dim test As String = "你的测试文本"

Dim mc As MatchCollection = Regex.Matches(test, ".*8.*", RegexOptions.Multiline) '找含8的行
For Each m As Match In mc
Debug.Print(m.Value)
Next




zj_zwl 2018-07-04
  • 打赏
  • 举报
回复
引用 5 楼 SennaWen 的回复:
[quote=引用 4 楼 zj_zwl 的回复:]


Imports System.Text.RegularExpressions

Dim test As String = "你的测试文本"

Dim mc As MatchCollection = Regex.Matches(test, ".*8.*", RegexOptions.Multiline) '找含8的行
For Each m As Match In mc
Debug.Print(m.Value)
Next






输出为字符串类型呢?[/quote]

现在输出就是字符串啊
余温生 2018-07-04
  • 打赏
  • 举报
回复
引用 4 楼 zj_zwl 的回复:


Imports System.Text.RegularExpressions

Dim test As String = "你的测试文本"

Dim mc As MatchCollection = Regex.Matches(test, ".*8.*", RegexOptions.Multiline) '找含8的行
For Each m As Match In mc
Debug.Print(m.Value)
Next






输出为字符串类型呢?
smileruner 2018-07-03
  • 打赏
  • 举报
回复
正则学起来花时间。可以考虑用contain,index啊。为什么要split呢。
余温生 2018-07-02
  • 打赏
  • 举报
回复
引用 1 楼 zj_zwl 的回复:
用正则吧 .*8.*
用多行模式


正则没学好,可以指教下么
zj_zwl 2018-07-02
  • 打赏
  • 举报
回复
用正则吧 .*8.*
用多行模式

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧