extracting a string from a string 
July 11th, 2008, 10: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 | 
July 12th, 2008, 04:45 AM
| | | | 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? | 
July 12th, 2008, 08:15 AM
| | | | 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 |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,689 network members.
|