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 str(1)
with the next word after position
th word in checkin
str(1)
if Dim valueSearch As String="to find a game" then
i have to display a message that "to find a"
is present My question is that is it possible to find the position of a word in a string using
string.Contains() operation. or any other possibility to implement this algorithm?
String.Contains(), INSTR or IndexOf should all do what you want
http://msdn.microsoft.com/en-us/library/dy85x1sa(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/8460tsh1(v=vs.90).aspx
Try Like this
Create recursive Method. Use String.Contains. Its true then return else continue the method.
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.