大家好,正如主题所示,我想在VB.net中执行一个仅从*.txt文件中获取数字的脚本
示例:
文本文件: asd4lkj5fdl jklj235
结果: 45235
我在Google上做了一个研究,什么也没想出来,我确实在这里看到了一个答案,但只在C中我知道理论上它需要是这样的:读取每个字符循环,询问它是否是整数,如果不是继续下一个字符,则将其添加到新字符串中,直到流的末尾
感谢你的帮助!
发布于 2013-06-22 05:51:10
Dim strTextFromFile As String = IO.File.ReadAllText("C:\filename.txt") Dim strTextFromFile As String = String.Empty For Each c As Char In strTextFromFile If IsNumeric(c) Then strResults += c End If Next Char If Next Char
发布于 2013-06-22 05:48:12
尝试正则表达式,不包含从文件中读取文本的代码
Dim rgx As New Regex("[^\d]")
Dim result as String = rgx.Replace("asd4lkj5fdl jklj235", "")发布于 2013-06-22 05:55:05
Public Sub Test()
Dim contents As String = File.ReadAllText("C:\\temp\\text.txt")
Dim digits As New String(contents.Where(Function(c) Char.IsDigit(c)).ToArray())
MessageBox.Show(digits)
End Subhttps://stackoverflow.com/questions/17244776
复制相似问题