Enabling partial name input to return values in c#
I have a c# web service that takes an String input and checks the input vs
a text document full of Strings.
It works as follows, lets say I input "Australia" into the input, the
service will return "Australia". However if I also input Aus (or aus,
currently made it case insensitive) it should also return "Australia".
On the other hand if I input "tra", it shouldn't return Australia, only
Strings that their first 3 indexes are "tra". (If it was Ch, it should
return China, Chad... etc)
Currently my code looks like
public String countryCode(String input)
{
StringBuilder strings = new StringBuilder("", 10000);
String text =
System.IO.File.ReadAllText(Server.MapPath("countryCodes.txt"));
String[] countries = Regex.Split(text, "#");
int v;
for (v = 0; v < countries.Length; v++)
{
if (countries[v].ToUpper().Contains(input) ||
countries[v].ToLower().Contains(input))
{
bool c = countries[v].ToUpper().Contains(input);
bool b = countries[v].ToLower().Contains(input);
if (b == true || c == true)
{
strings.Append(countries[v] + " ");
}
else
{
strings.Append("Country not found");
break;
}
}
}
String str = strings.ToString();
return str;
}
This is a start, but I am really having trouble comparing the indexes of
strings.
My question is how can I construct something to check countries[v][0] vs
input[0], if its the same, then check [1] and [1], and so on, until they
aren't the same or input.Length is exceeded then return values
appropriate?
Comment for clarifications if needed
Regards
No comments:
Post a Comment