+ Reply to Thread
Results 1 to 3 of 3

Substring based on position in string

Hybrid View

  1. #1
    Registered User
    Join Date
    05-21-2007
    Posts
    79

    Substring based on position in string

    I'm trying to figure out a way to cut a particular substring out of a string, based on the start and end points of the substring.

    For instance, I have code right now that will take in this example string:

    "abcde + 1234 abcde"

    And return two variables: a = 7 and b = 14. My variable a corresponds to finding the plus, and b corresponds to the first letter following the numbers.

    My aim is to write a function to read in that string, and return "+ 1234", based on knowing a and b.

    The only functions I know of with respect to strings are Mid, Len, Right/Left, and InStr, but none of them seem to read in a start and end point for substring finding. Right/Left would probably work, but I don't know how to cut the string from the right or the left using those.

    Thanks guys.

  2. #2
    mpeplow
    Guest
    Mid will work, try this.

    Sub Test_Mid_Function
    Dim a as integer
    Dim b as integer
    Dim Cut_String as String
    a = 7
    b = 14
    Cut_String = Mid("abcde + 1234 abcde",a,b)
    msgbox Cut_String
    End Sub

  3. #3
    Registered User
    Join Date
    05-21-2007
    Posts
    79
    Ah, mpeplow that was a good example! I changed it to

    Cut_String = Mid("abcde + 1234 abcde",a,b-a)
    Which works like a charm!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1