[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.
Re: Help get certain data from a long string
Will the file names always start with CMP_ and end with .txt?
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.
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
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.