开发者

Find if a string starts between two sections of Alphabet

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜