extracting a string from a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Per Juul Larsen

    extracting a string from a string

    hi.

    I do want to extract this string "abcdefg" from string
    "C:\dir1\dir2\a bcdefg-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

    #2
    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\a bcdefg-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\a bcdefg-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?

    Comment

    • Per Juul Larsen

      #3
      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\a bcdefg-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

      Comment

      Working...