dcsimg
Results 1 to 6 of 6

Thread: Find String Within a String

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    257

    Find String Within a String

    Hello,

    I need to find a way of finding a string within another string.

    For example, I have a variable 'Topic Name' with the value 'CB Computer Basics'.

    I want to be able to get just the string 'Computer Basics'. Is there a built-in function that can do this for me?

    P.S The InStr() function doesn't do the job.

    Thanks.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Find String Within a String

    Will you always need the last two items in the string?

    If not, how will the parsing routine know what to go after?

  3. #3
    Hyperactive Member BadgerBadger's Avatar
    Join Date
    Aug 2009
    Location
    Wales
    Posts
    382

    Re: Find String Within a String

    If you just want to know if the string exists within another string, check out the Contains method.
    "The only thing that interferes with my learning is my education."

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,902

    Re: Find String Within a String

    If you want to know WHERE it exists, also look at the IndexOf method. For more complex searches, take a look at RegEx, though that is a much more complex subject.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    257

    Re: Find String Within a String

    Finding out if a string contains another string is not what i'm looking for.

    Basically, I need to capture the string after the 5th character in another string.

    So,

    Original string = "(EL) English Lit"
    The String I Need = "English Lit"

    Quote Originally Posted by Hack View Post
    Will you always need the last two items in the string?
    Yes, and i'll always need to skip the first 5 characters.

    I hope this helps.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,902

    Re: Find String Within a String

    Then Hack had the more right question. If you can count on where the string will begin (always after the fifth character, for instance), then you can use SubString:

    st1 = st1.Substring(5)

    There are variations on substring if you want to get a fixed length string, but in the one shown, it will return the string beginning with character 5 (0-based counting, so I may be off by one for your example).
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width