![]() |
|
|
Welcome to the { mindfrost82.com } forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
extracting a string from a string
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 |
|
|||
|
Re: extracting a string from a string
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? |
|
|||
|
Re: extracting a string from a string
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 |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|