请问如何比较2个字符串的大小?

sheep88_fan 2006-11-10 05:00:13
请问如何比较2个字符串的大小?
...全文
231 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujia_0421 2006-11-10
  • 打赏
  • 举报
回复
直接用:CompareTo()
shoushii 2006-11-10
  • 打赏
  • 举报
回复
private static string CompareStrings( string str1, string str2 )
{

int cmpVal = str1.CompareTo(str2);
if (cmpVal == 0)
return "The strings have the same value!";
else if (cmpVal > 0)
return "The first string is greater than the second string!";
else
return "The second string is greater than the first string!";
}
lizhizhe2000 2006-11-10
  • 打赏
  • 举报
回复
private static string CompareStrings( string str1, string str2 )
{

int cmpVal = str1.CompareTo(str2);
if (cmpVal == 0)
return "The strings have the same value!";
else if (cmpVal > 0)
return "The first string is greater than the second string!";
else
return "The second string is greater than the first string!";
}
lizhizhe2000 2006-11-10
  • 打赏
  • 举报
回复
String.CompareTo()
blandlife 2006-11-10
  • 打赏
  • 举报
回复
string a;
string b;
if (a.Length>b.Length)
{...}

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧