Connecting Tech Pros Worldwide Help | Site Map

extracting a string from a string

  #1  
Old July 11th, 2008, 10:05 PM
Per Juul Larsen
Guest
 
Posts: 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
  #2  
Old July 12th, 2008, 04:45 AM
Jason Keats
Guest
 
Posts: n/a

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?
  #3  
Old July 12th, 2008, 08:15 AM
Per Juul Larsen
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Extracting string from URL Ananthu answers 2 July 29th, 2008 08:16 AM
extracting the sub string from a string ammmmmu answers 2 August 27th, 2007 12:30 PM
Extracting string from a file using C++ jbello123 answers 2 September 11th, 2006 06:45 PM
Extracting string John answers 7 July 11th, 2006 09:55 AM