By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,173 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

extracting a string from a string

P: n/a
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
Jul 11 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Per Juul Larsen wrote:
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?
Jul 12 '08 #2

P: n/a
Jason Keats skrev:
Per Juul Larsen wrote:
>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
Jul 12 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.