System.String.EndsWith 方法 (String, Boolean, CultureInfo)

方法描述

确定在使用指定的区域性进行比较时此字符串实例的结尾是否与指定的字符串匹配。

语法定义(C# System.String.EndsWith 方法 (String, Boolean, CultureInfo) 的用法)

public bool EndsWith(
	string value,
	bool ignoreCase,
	CultureInfo culture
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
value System-String 要与此实例末尾的子字符串进行比较的字符串。
ignoreCase System-Boolean 要在比较过程中忽略大小写,则为 true;否则为 false。
culture System-Globalization-CultureInfo 确定如何对此实例与 value 进行比较的区域性信息。如果 culture 为 null,则使用当前区域性。
返回值 System.Boolean 如果此字符串的末尾与 value 参数匹配,则为 true;否则为 false。

提示和注释

此方法将 value 参数与位于此字符串末尾、与 value 长度相同的子字符串进行比较,并返回指示它们是否相等的值。 若要相等,value 必须是对此同一实例的引用,或者与此字符串的末尾匹配。

此方法使用指定的大小写和区域性执行字(区分区域性)比较。

System.String.EndsWith 方法 (String, Boolean, CultureInfo)例子

使用影响搜索结果的区分大小写、不区分大小写和不同的区域性,多次调用 EndsWith 方法。

// 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

*/

异常

异常 异常描述
ArgumentNullException value 为 null。

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。