Connecting Tech Pros Worldwide Forums | Help | Site Map

extracting a string from a string

Per Juul Larsen
Guest
 
Posts: n/a
#1: Jul 11 '08
hi.

I do want to extract this string "abcdefg" from string
"C:\dir1\dir2\abcdefg-12345gsd"


Note : the length of the text string "abcdefg" may vary, but the last
character is always "-".
I need only the string "abcdefg" not "-12345gsd"

thanks pjl Denmark

Jason Keats
Guest
 
Posts: n/a
#2: Jul 12 '08

re: extracting a string from a string


Per Juul Larsen wrote:
Quote:
hi.
>
I do want to extract this string "abcdefg" from string
"C:\dir1\dir2\abcdefg-12345gsd"
>
>
Note : the length of the text string "abcdefg" may vary, but the last
character is always "-".
I need only the string "abcdefg" not "-12345gsd"
>
thanks pjl Denmark
Assuming you're using VB6...

Dim s As String
Dim n As Integer

s = "C:\dir1\dir2\abcdefg-12345gsd"
Debug.Print s

n = InStrRev(s, "\")
If n 0 Then
s = Mid$(s, n + 1)
Debug.Print s
End If

n = InStr(s, "-")
If n 0 Then
s = Left$(s, n - 1)
End If
Debug.Print s

Easy, wasn't it?
Per Juul Larsen
Guest
 
Posts: n/a
#3: Jul 12 '08

re: extracting a string from a string


Jason Keats skrev:
Quote:
Per Juul Larsen wrote:
Quote:
>hi.
>>
>I do want to extract this string "abcdefg" from string
>"C:\dir1\dir2\abcdefg-12345gsd"
>>
> Note : the length of the text string "abcdefg" may vary, but the
>last character is always "-".
>I need only the string "abcdefg" not "-12345gsd"
>>
>thanks pjl Denmark
>
Assuming you're using VB6...
>
Dim s As String
Dim n As Integer
>
s = "C:\dir1\dir2\abcdefg-12345gsd"
Debug.Print s
>
n = InStrRev(s, "\")
If n 0 Then
s = Mid$(s, n + 1)
Debug.Print s
End If
>
n = InStr(s, "-")
If n 0 Then
s = Left$(s, n - 1)
End If
Debug.Print s
>
Easy, wasn't it?
That Easy.. thanks
regards pjl
Closed Thread