开发者

Find if a string starts between two sections of Alphabet

开发者 https://www.devze.com 2023-01-29 11:15 出处:网络
What I开发者_C百科 am trying to do if find out if my string start is between two letters in the 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

精彩评论

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