String. Compare usage

Source: Internet
Author: User
  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"
  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 valid tive 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. //}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.