What I开发者_C百科 am trying to do if find out if my string start is between two letters in the alphabet
What I want is something like
mystring.StartsWith("a") but not greater that mystring.StartsWith("au")
That's fairly simple:
StringComparer comparer = StringComparer.Ordinal;
if (comparer.Compare(myString, "a") >= 0 &&
comparer.Compare(myString, "au") < 0)
{
// Do stuff
}
That will include "atzzzz" but not "au" itself. Adjust bounds as required - and likewise choose a different StringComparer
if necessary (e.g. a case-insensitive or culture-sensitive one).
精彩评论