Reputation: 431
I'm new to VB.net so please be patient with me. I'm trying extract all the ICN strings out of a text file and create a new text file with each ICN on a new line.
I've been able to read in the text file, but I don't know how to extract the REGEX and pull it into a new text file.
I appreciate your guidance in this.
Code so far:
Dim fileReader As System.IO.StreamReader
fileReader =
My.Computer.FileSystem.OpenTextFileReader("C:\\Test\\16 Move File out of folder\\GetICN.txt")
Dim stringReader As String
stringReader = fileReader.ReadToEnd()
REGEX to use:
(ICN-\w.*-\d+-\w+-\d+-\d\d)
Upvotes: 0
Views: 115
Reputation: 6452
Dim oldFileName = "C:\Test\16 Move File out of folder\GetICN.txt"
Dim newFileName = "C:\Test\16 Move File out of folder\GetICN2.txt"
Dim allText = System.IO.File.ReadAllText(oldFileName)
Dim matchs = System.Text.RegularExpressions.Regex.Matches(allText, "ICN-\w.*-\d+-\w+-\d+-\d\d")
Dim lines = matchs.Cast(Of System.Text.RegularExpressions.Match).Select(Function(m) m.Value)
System.IO.File.WriteAllLines(newFileName, lines)
Upvotes: 1