[英]Find position of a word in a string
我必須按照以下方法實施搜索,
讓:
Dim checkin As String = "This is the base string, i have to find a word here"
Dim valueSearch As String="to find a word"
現在要實現的算法是:
Position
=查找str(0)
位置 str(1)
與下一個單詞后position
日在字checkin
str(1)
if Dim valueSearch As String="to find a game" then
我必須顯示一條消息,指出存在"to find a"
我的問題是,是否有可能使用以下命令在字符串中找到單詞的位置
string.Contains()操作。 或其他實現此算法的可能性?
像這樣嘗試
創建遞歸方法。 使用String.Contains。 然后返回true,否則繼續該方法。
private Sub Recursive(ByVal xStr As String, ByVal xSearch As String)
If xStr.Contains(xSearch) Then
MsgBox(xSearch)
ElseIf xSearch.Contains(" ") Then
Recursive(xStr, xSearch.Substring(0, xSearch.LastIndexOf(" ")))
Else
MsgBox("Not Founded")
End If
End Sub
Call Recursive("This is the base string, i have to find a word here",
"to find a game")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.