Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.EndsWith Method (String, Boolean, CultureInfo)

Determines whether the end of this string matches the specified string when compared using the specified culture.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public bool EndsWith (
	string value,
	bool ignoreCase,
	CultureInfo culture
)
public boolean EndsWith (
	String value, 
	boolean ignoreCase, 
	CultureInfo culture
)
public function EndsWith (
	value : String, 
	ignoreCase : boolean, 
	culture : CultureInfo
) : boolean
Not applicable.

Parameters

value

A String object to compare to.

ignoreCase

true to ignore case when comparing this instance and value; otherwise, false.

culture

Cultural information that determines how this instance and value are compared. If culture is a null reference (Nothing in Visual Basic), the current culture is used.

Return Value

true if the value parameter matches the end of this string; otherwise, false.

Exception typeCondition

ArgumentNullException

value is a null reference (Nothing in Visual Basic).

This method compares the value parameter to the substring at the end of this string that is the same length as value, and returns a value that indicates whether they are equal. To be equal, value must be a reference to this same instance, or match the end of this string.

This method performs a word (culture-sensitive) comparison using the specified casing and culture.

The following code example determines whether a string occurs at the end of another string. The EndsWith method is called several times using case sensitivity, case insensitivity, and different cultures that influence the results of the search.

// This code example demonstrates the 
// System.String.EndsWith(String, ..., CultureInfo) method.

using System;
using System.Threading;
using System.Globalization;

class Sample 
{
    public static void Main() 
    {
    string msg1 = "Search for the target string \"{0}\" in the string \"{1}\".\n";
    string msg2 = "Using the {0} - \"{1}\" culture:";
    string msg3 = "  The string to search ends with the target string: {0}";
    bool result = false;
    CultureInfo ci;

// Define a target string to search for.
// U+00c5 = LATIN CAPITAL LETTER A WITH RING ABOVE
    string capitalARing = "\u00c5";

// Define a string to search. 
// The result of combining the characters LATIN SMALL LETTER A and COMBINING 
// RING ABOVE (U+0061, U+030a) is linguistically equivalent to the character 
// LATIN SMALL LETTER A WITH RING ABOVE (U+00e5).
    string xyzARing = "xyz" + "\u0061\u030a";

// Clear the screen and display an introduction.
    Console.Clear();

// Display the string to search for and the string to search.
    Console.WriteLine(msg1, capitalARing, xyzARing);

// Search using English-United States culture.
    ci = new CultureInfo("en-US");
    Console.WriteLine(msg2, ci.DisplayName, ci.Name);

    Console.WriteLine("Case sensitive:");
    result = xyzARing.EndsWith(capitalARing, false, ci);
    Console.WriteLine(msg3, result);

    Console.WriteLine("Case insensitive:");
    result = xyzARing.EndsWith(capitalARing, true, ci);
    Console.WriteLine(msg3, result);
    Console.WriteLine();

// Search using Swedish-Sweden culture.
    ci = new CultureInfo("sv-SE");
    Console.WriteLine(msg2, ci.DisplayName, ci.Name);

    Console.WriteLine("Case sensitive:");
    result = xyzARing.EndsWith(capitalARing, false, ci);
    Console.WriteLine(msg3, result);

    Console.WriteLine("Case insensitive:");
    result = xyzARing.EndsWith(capitalARing, true, ci);
    Console.WriteLine(msg3, result);
    }
}

/*
Note: This code example was executed on a console whose user interface 
culture is "en-US" (English-United States).

This code example produces the following results:

Search for the target string "Å" in the string "xyza°".

Using the English (United States) - "en-US" culture:
Case sensitive:
  The string to search ends with the target string: False
Case insensitive:
  The string to search ends with the target string: True

Using the Swedish (Sweden) - "sv-SE" culture:
Case sensitive:
  The string to search ends with the target string: False
Case insensitive:
  The string to search ends with the target string: False

*/

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

Show:
© 2014 Microsoft