On 13 May 2007 16:34:19 -0700, "ri***********@northwesternmutual.com"
<ri***********@northwesternmutual.comstaggered into the room,
obviously drunk, and said:
>I have the following string below in which I need to pull out the name
that follows: ContactsManager:" .
In this particular case it would be:
BARBARA JOSEPH
Job Completion, Failure Instructions, and Rerun NotesAppl ID
Description:dailyopsEdit Application ContactsManager: BARBARA JOSEPH
- Ext: 2612Primary: ISAAC THOMAS - Ext: 2011Secondary: RON MACDONALD -
Ext: 8759Edit Job ContactsPrimary: JEFF PETERS - Ext: 4908Secondary:
JOHN MAYER - Ext: 5104Tertiary: SUE WINTERS - Ext: 6978If this job
abends, notifyNext AM
thanks
This seems to work for me. It's using Regex.
Private Function ParseStrings(ByVal strings)
Dim re As New Regex("ContactsManager:\ ([^-]*\b)",
RegexOptions.IgnoreCase Or RegexOptions.Compiled)
Dim myMatch As Match = re.Match(strings)
If (myMatch.Success) Then
Return myMatch.Groups(1).Value
Else
Return "It's not here!"
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim theStrings As String
Dim readStrings As String
Dim readFile As New
System.IO.StreamReader(Application.StartupPath & "\strings.txt")
theStrings = readFile.ReadToEnd()
readStrings = ParseStrings(theStrings)
MsgBox(readStrings) ' Show BARBARA JOSEPH
readFile.Close()
End Sub
I've been able to use this to get the names following all of your
colons. For example...
Dim re As New Regex("Tertiary:\ ([^-]*\b)", RegexOptions.IgnoreCase Or
RegexOptions.Compiled)
This will return SUE WINTERS for me on my machine. Hopefully your
mileage will not vary too much.
I am still myself new to VB .NET, so if this doesn't perform as
expected, I am sorry.
Anyway, hope it DOES help.
Ryan
P.S.
If anyone can show me how to handle this method more efficiently, I
would love to see it. It will only help me learn better. :)