Results 1 to 5 of 5

Thread: [RESOLVED] Help get certain data from a long string

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    313

    Resolved [RESOLVED] Help get certain data from a long string

    I have a long string like this:
    CMP_0708114242.txt 9 3 5 9 3 0 6 9 - 9 5 2 2 9 8 6 - 3 3 7 4 _ C l a s s e s \ C L S I D \ { 0 A F A C E D 1 - E 8 2 8 - 1 1 D 1 - 9 1 8 7 - B 5 3 2 F 1 E 9 5 7 5 D } \ s h e l l e x \ I c o n H a n d l e r  ,´¨vd¶¨v CMP_100708113838.txt crosoft Network  T r a n s I m p l e m e n t a t i o n CMP_140708134343.txt 9 3 5 9 3 0 6 9 - 9 5 2 2 9 8 6 - 3 3 7 4 _ C l a s s e s \ I n t e r f a c e \ { 0 0 0 0 0 1 0 e - 0 0 0 0 - 0 0 0 0 - C 0 0 0 - 0 0 0 0 0 0 0 0 0 0 4 6 } \ P r o x y S t u b C l s i d 3 2 8¼n T r a n s I m p l e m e n t a t i o n CMP_150708145757.txt
    CMP_160708121919.txt Û# `Ü#  PÛ# xÜ#    " : \  ˆ ˆ M i n i p o r t ( P P T P )

    I need find those files with ".txt", How do I do it? Thanks.

  2. #2

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    313

    Re: Help get certain data from a long string

    Quote Originally Posted by MartinLiss
    Will the file names always start with CMP_ and end with .txt?
    Yes. But the number after CMP_ is not the same length. Thank you.
    Last edited by lucia; Jul 17th, 2008 at 11:13 AM.

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Help get certain data from a long string

    Code:
    Private Function ExtractCMP_xxxTxt(StrSrc As String) As String()
    Dim sBuf() As String, p0 As Long, p1 As Long, Ct As Long
    Const CHUNK = 16
       Do
          p0 = InStr(p0 + 1, StrSrc, "CMP_")
          If p0 Then
             p1 = InStr(p0 + 1, StrSrc, ".txt")
             If p1 Then
                If Ct Mod CHUNK = 0 Then ReDim Preserve sBuf(Ct + CHUNK - 1)
                sBuf(Ct) = Mid$(StrSrc, p0, p1 - p0 + 4)
                Ct = Ct + 1
             End If
          Else
             Exit Do
          End If
        Loop
        
        If Ct Then
          ReDim Preserve sBuf(Ct - 1)
        Else
          ReDim sBuf(-1 To -1) 'to show fail and to avoid subscript out of range
        End If
        GetCMP_xxxTxt = sBuf
    End Function

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    313

    Re: Help get certain data from a long string

    Quote Originally Posted by Milk
    Code:
    Private Function ExtractCMP_xxxTxt(StrSrc As String) As String()
    Dim sBuf() As String, p0 As Long, p1 As Long, Ct As Long
    Const CHUNK = 16
       Do
          p0 = InStr(p0 + 1, StrSrc, "CMP_")
          If p0 Then
             p1 = InStr(p0 + 1, StrSrc, ".txt")
             If p1 Then
                If Ct Mod CHUNK = 0 Then ReDim Preserve sBuf(Ct + CHUNK - 1)
                sBuf(Ct) = Mid$(StrSrc, p0, p1 - p0 + 4)
                Ct = Ct + 1
             End If
          Else
             Exit Do
          End If
        Loop
        
        If Ct Then
          ReDim Preserve sBuf(Ct - 1)
        Else
          ReDim sBuf(-1 To -1) 'to show fail and to avoid subscript out of range
        End If
        GetCMP_xxxTxt = sBuf
    End Function
    Thank you. I found the way to make the string more readable and easier to get what I want. I saved your code for future use.
    I appreciated your help.

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