[英]Find position of a word in a string
I have to implement a search in following method, 我必须按照以下方法实施搜索,
Let : 让:
Dim checkin As String = "This is the base string, i have to find a word here"
Dim valueSearch As String="to find a word"
Now the algorithm to be implemented is: 现在要实现的算法是:
Position
=Find Position of str(0)
in the string Position
=查找str(0)
位置 str(1)
with the next word after position
th word in checkin
str(1)
与下一个单词后position
日在字checkin
str(1)
str(1)
if Dim valueSearch As String="to find a game" then
i have to display a message that "to find a"
is present if Dim valueSearch As String="to find a game" then
我必须显示一条消息,指出存在"to find a"
My question is that is it possible to find the position of a word in a string using 我的问题是,是否有可能使用以下命令在字符串中找到单词的位置
string.Contains() operation. string.Contains()操作。 or any other possibility to implement this algorithm?
或其他实现此算法的可能性?
String.Contains(), INSTR or IndexOf should all do what you want String.Contains(),INSTR或IndexOf都应该做你想要的
http://msdn.microsoft.com/en-us/library/dy85x1sa(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/dy85x1sa(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/8460tsh1(v=vs.90).aspx http://msdn.microsoft.com/en-us/library/8460tsh1(v=vs.90).aspx
http://msdn.microsoft.com/en-us/library/2y7ddk24.aspx http://msdn.microsoft.com/en-us/library/2y7ddk24.aspx
Try Like this 像这样尝试
Create recursive Method. 创建递归方法。 Use String.Contains.
使用String.Contains。 Its true then return else continue the method.
然后返回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.