Compare substring in CSharp

Description

The following code shows how to compare substring.

Example


/* w w  w  .  ja  v a  2s.co  m*/
using System;

class Sample {
    public static void Main() {
        String str1 = "this is a test";
        String str2 = "This is a test";
        String str;
        int result;
    
        result = String.Compare(str1, 2, str2, 2, 2, true);
        str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));
        Console.Write("Substring '{0}' in '{1}' is ", str1.Substring(2, 2), str1);
        Console.Write("{0} ", str);
        Console.WriteLine("substring '{0}' in '{1}'.", str2.Substring(2, 2), str2);
    
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var