VB .NET String Manipulation

I have the following phrases for example:

This is a test for wordA.
This is a test for wordB.

I need to grab the phrase before wordA OR wordB.  So my output for both sentences would be "This is a test for".  I need it to look for both wordA and wordB, grabbing the phrase before either word.
LVL 16
disruptAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can use the plain old Split() function.  Everything before your word will at Index 0 (zero):
Dim word As String = "wordA"
        Dim str As String = "This is a test for wordA."
        Dim values() As String = str.Split(word)
        Dim phrase As String = values(0)
        MessageBox.Show(phrase)

Open in new window

0
 
edemcsCommented:
You may use String.SubString, start at position 0, and your max limit will me the IndexOf("wordA") or IndexOf("wordB")
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.