String.Compare的用法

  1. Console.WriteLine("*******************String.CompareTo()*********************");
  2.             String strTestCompare = "abc";
  3.             //strTestCompare.CompareTo("abc")=0
  4.             //strTestCompare.CompareTo("ab")=1
  5.             //strTestCompare.CompareTo("a")=1
  6.             //strTestCompare.CompareTo("b")=-1
  7.             //String.Compare("abc", "a")=1
  8.             //String.Compare("abc", "ab")=1
  9.             //String.Compare("abc", "abc")=0
  10.             //String.Compare("abc", "b")=-1
  11.             Console.WriteLine(String.Compare("abc""abc").ToString());
  12.             Console.WriteLine("*******************String.CompareTo()********End**********");
  13.             //String.Compare from MSDN
  14.             //unsafe
  15.             //{
  16.             //    // Null terminated ASCII characters in an sbyte array
  17.             //    String szAsciiUpper = null;
  18.             //    sbyte[] sbArr1 = new sbyte[] { 0x41, 0x42, 0x43, 0x00 };
  19.             //    // Instruct the Garbage Collector not to move the memory
  20.             //    fixed (sbyte* pAsciiUpper = sbArr1)
  21.             //    {
  22.             //        szAsciiUpper = new String(pAsciiUpper);
  23.             //    }
  24.             //    String szAsciiLower = null;
  25.             //    sbyte[] sbArr2 = { 0x61, 0x62, 0x63, 0x00 };
  26.             //    // Instruct the Garbage Collector not to move the memory
  27.             //    fixed (sbyte* pAsciiLower = sbArr2)
  28.             //    {
  29.             //        szAsciiLower = new String(pAsciiLower, 0, sbArr2.Length);
  30.             //    }
  31.             //    // Prints "ABC abc"
  32.             //    Console.WriteLine(szAsciiUpper + " " + szAsciiLower);
  33.             //    // Compare Strings - the result is true
  34.             //    Console.WriteLine("The Strings are equal when capitalized ? " +
  35.             //        (String.Compare(szAsciiUpper.ToUpper(), szAsciiLower.ToUpper()) == 0 ? "true" : "false"));
  36.             //    // This is the effective equivalent of another Compare method, which ignores case
  37.             //    Console.WriteLine("The Strings are equal when capitalized ? " +
  38.             //        (String.Compare(szAsciiUpper, szAsciiLower, true) == 0 ? "true" : "false"));
  39.             //}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值