0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

正規表現の代わりのユーザー定義関数

Posted at
Function ExtractAllBetween(text As String, startStr As String, endStr As String, Optional delimiter As String = ",") As String
    Dim result As String
    Dim startPos As Long, endPos As Long
    Dim currentPos As Long
    Dim temp As String

    result = ""
    currentPos = 1

    Do
        startPos = InStr(currentPos, text, startStr)
        If startPos = 0 Then Exit Do
        
        startPos = startPos + Len(startStr)
        endPos = InStr(startPos, text, endStr)
        If endPos = 0 Then Exit Do
        
        temp = Mid(text, startPos, endPos - startPos)
        
        If result = "" Then
            result = temp
        Else
            result = result & delimiter & temp
        End If

        currentPos = endPos + Len(endStr)
    Loop

    ExtractAllBetween = result
End Function
こめん
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?