How would I remove the text between two given strings
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 'String Manipulation - How would I remove the text between two given strings Private Sub Form_Load() Dim s As String s = "Before<Between>After<Between>More" Debug.Print RemoveBetween(s, "<", ">") End Function Private Function RemoveBetween(ByVal sText As String, ByVal sStart As String, _ ByVal sFinish As String) As String Dim lStart As Long, lEnd As Long, lLen As Long Do lStart = InStr(sText, sStart) If lStart Then lEnd = InStr(lStart + Len(sStart), sText, sFinish) If lEnd Then lLen = lEnd - lStart + Len(sFinish) Mid$(sText, lStart, lLen) = String$(lLen, vbNullChar) End If End If Loop Until lStart = 0 Or lEnd = 0 RemoveBetween = Replace(sText, vbNullChar, vbNullString) End Function |