Advertisement
3_2004-2005 String Manipulation #134978

GetTag, GetTagText, CutTag

This is a set of three functions that pull tagged data, such as that from HTML or XML, based on the tag name. I've used this in a number of applications where I've need to store multiple bits of variable-length data in a single string or file.

AI

ملخص الذكاء الاصطناعي: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

كود المصدر
original-source
Public Function GetTag(SourceString As String, Tag As String) As String
  'Gets the tag and text between it
  If InStr(SourceString, "<" & Tag & ">") = 0 Then
    GetTag = ""
    Exit Function
  End If
  GetTag = Mid$(SourceString, InStr(SourceString, "<" & Tag & ">"), InStr(SourceString, "</" & Tag & ">") + Len("</" & Tag & ">") - 1)
End Function
Public Function GetTagText(SourceString As String, Tag As String) As String
  'Grabs the text between tags
  If InStr(SourceString, "<" & Tag & ">") = 0 Then
    GetTagText = ""
    Exit Function
  End If
  GetTagText = Mid$(SourceString, InStr(SourceString, "<" & Tag & ">") + Len("<" & Tag & ">"), (InStr(SourceString, "</" & Tag & ">")) - (InStr(SourceString, "<" & Tag & ">") + Len("<" & Tag & ">")))
End Function
 Public Function CutTag(SourceString As String, Tag As String) As String
  'Cuts the entire tag out of the text
  If InStr(SourceString, "<" & Tag & ">") = 0 Then
    CutTag = ""
    Exit Function
  End If
  CutTag = Left$(SourceString, InStr(SourceString, "<" & Tag & ">") - 1) & Mid$(SourceString, InStrRev(SourceString, "</" & Tag & ">") + Len("</" & Tag & ">"))
End Function
التعليقات الأصلية (3)
مسترجع من Wayback Machine