Tag処理

Tag処理は複雑でまとめるのが大変なので、とりあえず ここでは2種類の区切り文字列に挟まれた文字列を取り出すプロシージャのサンプルを紹介します。
次のサンプルは入力文字列InTxtに対して区切り文字列preDemとposDemに挟まれた文字列をOutTxtとして戻します。区切り文字列が見つからなかったらStatusにFalseを設定します。続きの文字列の位置をnextPosに設定します。
例えば"<" と ">"に挟まれた文字列"TAG"を取り出した後、"<TAG>"と"</TAG>"に挟まれた文字列を取り出すことができ、簡易なTAG処理に利用できます。

Public Sub example1701(InTxt As String, OutTxt As String, preDem As String, _
      posDem As String, Status As Boolean, nextPos As Integer)
   Dim searchPos As Integer, endPos As Integer

      searchPos = InStr(1, InTxt, preDem)
      If searchPos > 0 Then
         endPos = InStr(searchPos + Len(preDem), InTxt, posDem)
         If endPos = 0 Then
            Status = False
         Else
            Status = True
            OutTxt = Trim(Mid(InTxt, searchPos + Len(preDem), endPos - searchPos - Len(preDem)))
            nextPos = endPos + Len(posDem)
         End If
      Else
         Status = False
      End If

End Sub

最終更新のRSS
Last-modified: 2014-03-11 (火) 01:58:42 (3698d)