Write a C# program to compare (less than, greater than, equal to ) two substrings


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2.  
  3. class StringExample
  4. {
  5. public static void Main()
  6. {
  7.  
  8. String str1 = "computer";
  9. String str2 = "system";
  10. String str;
  11. int result;
  12.  
  13. Console.WriteLine();
  14. Console.WriteLine("str1 = '{0}', str2 = '{1}'", str1, str2);
  15. result = String.Compare(str1, 2, str2, 0, 2);
  16. str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));
  17. Console.Write("Substring '{0}' in '{1}' is ", str1.Substring(2, 2), str1);
  18. Console.Write("{0} ", str);
  19. Console.WriteLine("substring '{0}' in '{1}'.", str2.Substring(0, 2), str2);
  20.  
  21. Console.ReadLine();
  22. }
  23. }

Result

C# language techstudy

     





Related Topics




Popular Posts