本文章是由機器翻譯。 將指標移到文章內的文字上方即可查看原文。 其他資訊。
譯文
原文
資訊
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 方法 (String, Boolean, CultureInfo)

判斷當使用指定之文化特性進行比較時,這個字串執行個體的結尾是否符合指定的字串。

命名空間:  System
組件:  mscorlib (在 mscorlib.dll 中)

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

參數

value
類型:System.String
要在這個執行個體結尾與子字串比較的字串。
ignoreCase
類型:System.Boolean
若要在比較時忽略大小寫,則為 true,否則為 false
culture
類型:System.Globalization.CultureInfo
判斷此執行個體和 value 如何進行比較的文化特性資訊。 如果 culturenull,則會使用目前的文化特性。

傳回值

類型:System.Boolean
如果 value 參數符合這個字串的結尾,則為 true,否則為 false

例外狀況條件
ArgumentNullException

valuenull

這個方法會比較 value 參數以及在此字串結尾與 value 長度相同的子字串,並傳回值,指出二者是否相等。 value 必須為這個相同執行個體的參考,或是必須符合此字串的結尾,兩者才會相等。

此方法會使用指定之大小寫和文化特性,執行字組 (區分文化特性) 比較。

下列範例會判斷字串是否位於另一個字串的結尾。 使用區分大小寫、不區分大小寫和影響搜尋結果的不同文化特性,呼叫 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

*/


.NET Framework

支援版本:4.5.2、4.5.1、4.5、4、3.5、3.0、2.0

.NET Framework Client Profile

支援版本:4、3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (不支援伺服器核心角色), Windows Server 2008 R2 (SP1 (含) 以後版本支援伺服器核心角色,不支援 Itanium)

.NET Framework 並不支援各種平台的所有版本。如需支援版本的清單,請參閱.NET Framework 系統需求

社群新增項目

顯示:
© 2015 Microsoft