WPCap
asked on
VB.NET CUSTOM - check if string contains substring.
Hi there.
I have a string:
For example the output should be: string "dThatI" was found in: WordThatIneed
I have a string:
word1 word2 word3120dafsog jsdgjidasggjd WordThatIneed ifahfiashd.
The string is always random and let's assume that I'm looking for word dThatI. Now I have a code that is looking for dThatI in the whole string, but how can I display where that "dThatI" was found.
For example the output should be: string "dThatI" was found in: WordThatIneed
change str.contains
to
WordThatIneed.contains
to
WordThatIneed.contains
ASKER
I think I wasn't clear enough in the topic.
Let's say I have string
str = "something here and here but here is the wordthatIneed"
now I need to first check if str contains dthati and if it does, then I need to know where "dthati" was found.
So the output should be:
dthati was found in str in a word: wordthatineed.
Let's say I have string
str = "something here and here but here is the wordthatIneed"
now I need to first check if str contains dthati and if it does, then I need to know where "dthati" was found.
So the output should be:
dthati was found in str in a word: wordthatineed.
Ok for this, you nees to split the string and store into array. And loop the array contents and check with contains method
ASKER
I have no idea how to do that.
Let me give the code, once I reach home.,another 30 mins
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Module Module1
Sub Main()
Dim str As String
Dim strArr() As String
str = "something here and here but here is the wordthatIneed"
strArr = str.Split(" ")
For count = 0 To strArr.Length - 1
If (strArr(count).Contains("thatI")) Then
MsgBox("thatI contains in " & strArr(count))
End If
Next
End Sub
End Module
Open in new window