Dim strTextTag="Terminology <VN_CR NO="1"/>for test in the glossary. Terminology <VN_F NO="1"><VN_CR NO="2"/></VN_F>for test"
Dim strText="Terminology for test in the glossary. Terminology for test"
Dim strValue="Terminology for test"
我如何首先:
在搜索之前删除[<VN_CR NO="1"/>
]和[<VN_F NO="1"><VN_CR NO="2"/></VN_F>
]。
如果strValue
中存在strTextTag
,我如何获得strValue
中所有strText
的排名?
答案 0 :(得分:-1)
您可以使用RegEx.Replace
查找并删除所有代码。并使用Regex.Matches
函数查找另一个字符串中出现的所有字符串。
Function RemoveTags(ByVal textWithTags As String) As String
Dim result As String = Regex.Replace(textWithTags, "<[^>]+?>", " ") '-- remove the tags
result = result.Replace(" ", " ") '-- remove any extra whitespaces that might have got in due to regex replacement
Return result
End Function
Function GetTextPositions(ByVal text As String, ByVal find As String) As Integer()
Dim result As New List(Of Integer)
Dim re As New Regex(Regex.Escape(find))
For Each match As Match In re.Matches(text)
result.Add(match.Index)
Next
Return result.ToArray
End Function