473,396 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using Regexp or Instr to pull out a substring from a string

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

May 13 '07 #1
2 2359
Richard,

Here is a way of doing it, but I am sure there is a simplier way too:

Dim strFull As String = "Job Completion, Failure Instructions, and
Rerun NotesAppl ID Description: dailyopsEdit Application ContactsManager:
BARBARA JOSEPH - Ext: 2612Primary: ISAAC THOMAS - Ext: 2011" ' Cut down for
convenience
Dim intJob As Integer = strFull.IndexOf("ContactsManager:") ' Index
= 100
Dim intStart As Integer = intJob + 17 ' Start of name
Dim intHyphen As Integer = strFull.IndexOf("-") - 1 ' After Contacts
Manager's name (trimming the space)
Dim intLength As Integer = intHyphen - intStart ' Length of name
Dim strName As String = strFull.Substring(intStart, intLength) '
Find name
MessageBox.Show(strName, "Application Contacts Manager:") ' Display

--
Newbie Coder
(It's just a name)

<ri***********@northwesternmutual.comwrote in message
news:11**********************@w5g2000hsg.googlegro ups.com...
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

May 14 '07 #2
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. :)
May 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
11
by: rajarao | last post by:
hi I want to remove the content embedded in <script> and </script> tags submitted via text box. My java script should remove the content embedded between <script> and </script> tag. my current...
20
by: RobG | last post by:
I'm messing with getPropertyValue (Mozilla et al) and currentStyle (IE) and have a general function (slightly modified from one originally posted by Steve van Dongen) for getting style properties:...
4
by: Gordon | last post by:
Hi; I am trying to extract a substring using a combination of the mid() and Instr() i.e. aString = "Jones, Thomas R, Dr." hold = InStr(1, aString, " ," , 1) newString = Mid(aString, 1,...
0
by: mookie | last post by:
m looking to create something similar to #region and #endregion using treeviews the problem is that instead of #region, i am using ;fold and ;endfold i am also allowed ot have a fold within...
7
by: arno | last post by:
Hi, I want to search a substring within a string : fonction (str, substr) { if (str.search(substr) != -1) { // do something } }
0
by: sirjohnofthewest | last post by:
This function will give you 100% control over the QueryString -- perfect for programmers who use QueryString manipulation a lot. I wrote this function when I kept having to change values of the...
4
by: Andrew Poulos | last post by:
I have a string that looks like this "cmi.interactions.fred.id" I need to test that: - the first part of the string is "cmi.interactions." (case sensitive). - the last part of the string is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.