VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Find text in tags

by Jason Yong (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This is just a simple code to find the text in a tag. like, [tag] I'm a tag![/tag]

Inputs
Text = is the string to search StartTag = is the first part of the tag to look for. like [tag] EndTag = Is the end tag like [/tag] 'it will return different values depending on the ReturnCode
Code Returns
if ReturnCode = 1 will return the text 2 will return where the first tag starts 3 will return where the text in the tag starts 4 will return where the tag ends

Rate Find text in tags

'=================InTag Function====================
'=================================
'(C) Jason Yong 2003
'=================================
'This function will find what text is in a tag, like [b]this[/b]
'it will return different values depending on the ReturnCode
'ReturnCode = 1 will return the text
' 2 will return where the first tag starts
' 3 will return where the text in the tag starts
' 4 will return where the tag ends.
'===================================================
Function InTag(Text As String, StartTag As String, EndTag As String, ReturnCode As Integer) As String
Dim t As Long
Dim r As Long
 For t = 1 To Len(Text)
 If Mid(Text, t, Len(StartTag)) = StartTag Then
  For r = t To Len(Text)
  If Mid(Text, r, Len(EndTag)) = EndTag Then
   If ReturnCode = 1 Or ReturnCode = 0 Then InTag = Mid(Text, t + Len(StartTag), r - (t + Len(StartTag)))
   If ReturnCode = 2 Then InTag = Str(t)
   If ReturnCode = 3 Then InTag = Str(t) + Len(StartTag)
   If ReturnCode = 4 Then InTag = Str(r - (t + Len(StartTag) + Len(EndTag)))
  End If
  Next
 End If
 Next
End Function

Download this snippet    Add to My Saved Code

Find text in tags Comments

No comments have been posted about Find text in tags. Why not be the first to post a comment about Find text in tags.

Post your comment

Subject:
Message:
0/1000 characters