VB .NET String Manipulation

Posted on 2011-05-04
Last Modified: 2012-05-11
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.
Question by:disrupt
    LVL 8

    Expert Comment

    You may use String.SubString, start at position 0, and your max limit will me the IndexOf("wordA") or IndexOf("wordB")
    LVL 85

    Accepted Solution

    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)

    Open in new window


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now