Hi,
I am trying to isolate printer names within a text file created via "Net View \\Print-Server > (path).printer.txt
I found a post on regular expressions, which seems like the way to go with this, however, I cant isolate the info I want. her is what i have written (mostly coppied and altered):
Dim tr As TextReader
tr = File.OpenText("(path)\printers.txt")
Dim test As String = tr.ReadToEnd()
Dim mx As Match
Dim pattern As String = Chr(13) & "*" & "Print"
For Each mx In Regex.Matches(test, pattern, RegexOptions.Multiline)
Console.WriteLine("*", mx.Value, mx.Groups("*").Value)
'here I've tried "Share Name" as a group too to no avail
TextBox1.AppendText(mx.Groups("Share Name").Value)
TextBox1.AppendText(vbCrLf)
Next
I get a long list of "Print" when I run this, I'm trying to generate the text (printer name) prior to the "Print" ideally with all spaces between the "printer name" and the "Print" removed. Below is an example of the text output:
I don't know if it matters much to say but some of the printer names have spaces in them so this cant simply remove all spaces on a line prior to the "Print"
Additionally,each printer name is unique (I suppose that is obvious :) and there isn't even a real naming convention in place so i can't imagine how to create a pattern for the computer name except that it occurs after a 'chr(13)' and before a "Print"
Shared resources at \\Print-ServerName
Share name Type Used as Comment
-------------------------------------------------------------------------------
PrinterName1 Print PrinterName1
PrinterName2 Print PrinterName2
PrinterName3 Print PrinterName3
PrinterName4 Print PrinterName4
PrinterName5 Print PrinterName5
PrinterName6 Print PrinterName6
Any help would be greatly appreciated