Reputation: 3376
I am creating a search application which searches a collection from a given string + *
For example I have this string collection:
SMITH
SMATH
BATH
SMAG
x
Test
When the user input *TH the output should be SMITH, SMATH and BATH
When the user input SM*TH the output should be SMITH and SMATH
When the user input SM* the output should be SMITH, SMATH and SMAG
Do you have any suggestion on how to do this?
Upvotes: 0
Views: 3731
Reputation: 8378
Have a look at regular expressions in .NET
If you only have a wildcard * I'd probably replace this with a .* (0 or more characters) or a .+ (1 or more characters) in the first instance
something like (not tested but should have all the elements to get you going)
var pattern = "SM*TH";
var newpattern = pattern.Replace("*",".+");
var rex = new RegEx(newpattern);
var match = rex.Match("SMITH")
Upvotes: 1