Mono Class Library: System.String Overview | Members

System.String.EndsWith Method

Returns a bool value that indicates whether the ending characters of the current instance match the specified string. [Edit]

public bool EndsWith (string value)

Parameters

value
A string to match. [Edit]

Returns

true if the end of the current instance is equal to value; false if value is not equal to the end of the current instance or is longer than the current instance. [Edit]

Exceptions

TypeReason
ArgumentNullExceptionvalue is a null reference. [Edit]

Remarks

This method compares value with the substring at the end of the current instance that has a same length as value.

The comparison is case-sensitive.

[Edit]

Example

The following example demonstrates determining whether the current instance ends with a specified string.

C# Example
using System;
public class StringEndsWithExample {
 public static void Main() {
 string str = "One string to compare";
 Console.WriteLine( "The given string is '{0}'", str );
 Console.Write( "The given string ends with 'compare'? " );
 Console.WriteLine( str.EndsWith( "compare" ) );
 Console.Write( "The given string ends with 'Compare'? " );
 Console.WriteLine( str.EndsWith( "Compare" ) );
 }
}
   

The output is

The given string is 'One string to compare'
The given string ends with 'compare'? True
The given string ends with 'Compare'? False

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0