C# Sharp Exercises: Perform an ordinal comparison of two strings that only differ in case
C# Sharp String: Exercise-31 with Solution
Write a C# Sharp program to perform and ordinal comparison of two strings that only differ in case.
Sample Solution:-
C# Sharp Code:
using System;
class Example31
{
public static void Main() {
String str1 = "JAVA";
String str2 = "python";
String str;
int result;
Console.WriteLine();
Console.WriteLine("Compare the numeric values of the corresponding Char objects in each string.");
Console.WriteLine("str1 = '{0}', str2 = '{1}'", str1, str2);
result = String.CompareOrdinal(str1, str2);
str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));
Console.Write("String '{0}' is ", str1);
Console.Write("{0} ", str);
Console.WriteLine("String '{0}'.", str2);
}
}
Sample Output:
Compare the numeric values of the corresponding Char objects in each string. str1 = 'JAVA', str2 = 'python' String 'JAVA' is less than String 'python'.
Flowchart :
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to demonstrate that CompareOrdinal and Compare use different sort orders.
Next: Write a C# Sharp program to compare a given string with set of strings.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework