C# 中,针对数据串数据排序,要字母区分大小写,
如string[]s={"a","A","ab","aB","Ab","AB","b","B"};则应输出{"A","AB","Ab","B","a","aB","ab"...
如string[] s = { "a", "A", "ab", "aB", "Ab", "AB", "b", "B" };则应输出{"A","AB","Ab","B","a","aB","ab","b"}
展开
1个回答
展开全部
我试了下,直接进行排序,返回结果却是
string[] s = { "a", "A", "ab", "aB", "Ab", "AB", "b", "B" };
Array.Sort(s) //返回{"a","A","ab","aB","Ab","AB","b","B",}
后来查了下资料,可能是区域性设置问题,改了下就正确了:
Array.Sort(s, (a, b) => string.Compare(a, b, StringComparison.Ordinal));
//返回{"A","AB","Ab","B","a","aB","ab","b"}
Array.Sort(s, (a, b) => string.CompareOrdinal(a, b));
//上面这句话也是对的
如满意,请采纳,谢谢。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |