How can I search for a string inside another one and then select all the characters till end of line ? For example, given this string:
PrinterName: PDFCreator
PortName: PDFCreator:
Status: Unknown
DriverName: PDFCreator
PrinterName: Lexmark E360dn XL
PortName: someport
Status: Unknown
DriverName: Lexmark E360dn XL
HostAddress: somehostaddress
I'd like to search the string: "PrinterName" once it finds it, add it into a combobox, in order to get only the PrinterName. So far i wrote this:
Dim TextSearched As String = tmp.Text
Dim Paragraph As String = "PrinterName:"
Dim location As Integer = 0
Dim occurances As Integer = 0
Do
location = TextSearched.IndexOf(Paragraph, location)
If location <> -1 Then
occurances += 1
If TextSearched.EndsWith(vbCrLf) Then
Debug.Print(TextSearched.Substring(location, TextSearched.IndexOf(vbCrLf)))
End If
location += Paragraph.Length
End If
Loop Until location = -1
where tmp.Text is a long string like the example above.
When i run it I get something like this:
PrinterName: PDFCreator
PrinterName: Lexmark E3
I don't get the "360dn XL"