[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

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.
0
disrupt
Asked:
disrupt
1 Solution
 
edemcsCommented:
You may use String.SubString, start at position 0, and your max limit will me the IndexOf("wordA") or IndexOf("wordB")
0
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now