Results 1 to 6 of 6

Thread: string manipulation

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    122

    string manipulation

    Hi all ,

    I have a simple question I am working with a string that looks like

    " 1/2X014 AB tape". I want to pull out AB from the string and run a query. The length of the string changes from time to time but I want to keep track of two alphabets.

    Need ur inputs on this ....

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: string manipulation

    If there is always a space before and after, you can just use Split()

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim str() As String
    5.   Dim a As String
    6.   a = Trim$(" 1/2X014 AB tape") ' deletes leading and trailing spaces
    7.   str() = Split(a, " ")
    8.   MsgBox str(1)
    9. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    122

    Re: string manipulation

    iam working in VBA environment and the split function is throwing me an exception as sub or function not defined.

    need ur thoughts on this ..... thanks

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: string manipulation

    There is a Split function here that you can use in VBA.

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: string manipulation

    This should work just as well.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim str() As String
    5.   Dim a As String, sStart As Integer, sEnd As Integer
    6.   a = Trim$(" 1/2X014 AB tape") ' deletes leading and trailing spaces
    7.   sStart = InStr(1, a, " ")
    8.   sEnd = InStr(sStart + 1, a, " ")
    9.   MsgBox Mid$(a, sStart, sEnd - sStart)
    10. End Sub

  6. #6

Posting Permissions

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



Click Here to Expand Forum to Full Width