Hi,
Break your search string into an array of words e.g. an apple would become an array with two items {"an", "apple"}. Check your second string for each item in the array by looping through it and if it is true in every case you have a match.
for(int i = 0; i<array.length;i++) {
if(string2.contains(array[i]) {
boolean == true
} else {
boolean == false
}
}
If the boolean value every becomes false you don't have a match.
Hope that helps,
hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 167
You mean that all the letters from string1 are in string2?
Is so, hericles solution will work, but partly, you need a break point of the for loop, when all indexes are reached.
hericles`s code needs to be modified a bit (and in VB):
Dim s1 As String = "an apple"
Dim s2 As String = "each apple is not an issue"
Dim s1Array As String() = s1.Split(" "C)
Dim bContains As Boolean = False
For i As Integer = 0 To s1Array.Length - 1
If s2.Contains(s1Array(i)) Then
bContains = True
Else
Exit For
End If
Next
If bContains Then
Console.WriteLine("All words that are in s1 are in s2 as well.")
Else
Console.WriteLine("s2 does NOT contain all words from s1.")
End If
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474