Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

extracting a string from a string

Question posted by: Per Juul Larsen (Guest) on July 11th, 2008 09:05 PM
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's Avatar
Jason Keats
Guest
n/a Posts
July 12th, 2008
03:45 AM
#2

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's Avatar
Per Juul Larsen
Guest
n/a Posts
July 12th, 2008
07:15 AM
#3

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

 
Not the answer you were looking for? Post your question . . .
190,473 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors