翻訳への提案を行います
 
他のユーザーによる提案:

progress indicator
他の提案はありません。
クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 4
System
String クラス
String メソッド
EndsWith メソッド
 EndsWith メソッド (String)
すべて縮小/すべて展開 すべて縮小
コンテンツの表示:   英語と日本語を並べて表示コンテンツの表示: 英語と日本語を並べて表示
.NET Framework Class Library
String..::.EndsWith Method (String)

Determines whether the end of this string instance matches the specified string.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic
Public Function EndsWith ( _
    value As String _
) As Boolean
C#
public bool EndsWith(
    string value
)
Visual C++
public:
bool EndsWith(
    String^ value
)
F#
member EndsWith : 
        value:string -> bool 

Parameters

value
Type: System..::.String
The string to compare to the substring at the end of this instance.

Return Value

Type: System..::.Boolean
true if value matches the end of this instance; otherwise, false.
ExceptionCondition
ArgumentNullException

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

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

This method performs a word (case-sensitive and culture-sensitive) comparison using the current culture.

Notes to Callers

As explained in Best Practices for Using Strings in the .NET Framework, we recommend that you avoid calling string comparison methods that substitute default values and instead call methods that require parameters to be explicitly specified. To determine whether a string ends with a particular substring by using the string comparison rules of the current culture, call the EndsWith(String, StringComparison) method overload with a value of StringComparison..::.CurrentCulture for its comparisonType parameter.

The following example demonstrates how you can use the EndsWith method as part of a routine that removes HTML end tags from the end of a line.

Visual Basic
Imports System

Public Class EndsWithTest
    Public Shared Sub Main()
        Dim strSource() As String = { "<b>This is bold text</b>", _
                    "<H1>This is large Text</H1>", _
                    "<b><i><font color = green>This has multiple tags</font></i></b>", _
                    "<b>This has <i>embedded</i> tags.</b>", _
                    "This line simply ends with a greater than symbol, it should not be modified>"}

        Console.WriteLine("The following lists the items before the ends have been stripped:")
        Console.WriteLine("-----------------------------------------------------------------")

        ' Display the initial array of strings.
        For Each s As String In  strSource
            Console.WriteLine(s)
        Next
        Console.WriteLine()

        Console.WriteLine("The following lists the items after the ends have been stripped:")
        Console.WriteLine("----------------------------------------------------------------")

        ' Display the array of strings.
        For Each s As String In strSource
            Console.WriteLine(StripEndTags(s))
        Next 
    End Sub 

    Private Shared Function StripEndTags(item As String) As String
        ' Try to find a tag at the end of the line using EndsWith.
        If item.Trim().EndsWith(">") Then
            ' now search for the opening tag...
            Dim lastLocation As Integer = item.LastIndexOf("</")
            If lastLocation >= 0 Then

                ' Remove the identified section, if it is a valid region.
                item = item.Substring(0, lastLocation)
            End If
        End If
       Return Item
    End Function 
End Class
' The example displays the following output:
'    The following lists the items before the ends have been stripped:
'    -----------------------------------------------------------------
'    <b>This is bold text</b>
'    <H1>This is large Text</H1>
'    <b><i><font color = green>This has multiple tags</font></i></b>
'    <b>This has <i>embedded</i> tags.</b>
'    This line simply ends with a greater than symbol, it should not be modified>
'    
'    The following lists the items after the ends have been stripped:
'    ----------------------------------------------------------------
'    <b>This is bold text
'    <H1>This is large Text
'    <b><i><font color = green>This has multiple tags</font></i>
'    <b>This has <i>embedded</i> tags.
'    This line simply ends with a greater than symbol, it should not be modified>
C#
using System;

public class EndsWithTest {
    public static void Main() {

        // process an input file that contains html tags.
        // this sample checks for multiple tags at the end of the line, rather than simply
        // removing the last one.
        // note: HTML markup tags always end in a greater than symbol (>).

        string [] strSource = { "<b>This is bold text</b>", "<H1>This is large Text</H1>",
                "<b><i><font color=green>This has multiple tags</font></i></b>",
                "<b>This has <i>embedded</i> tags.</b>",
                "This line simply ends with a greater than symbol, it should not be modified>" };

        Console.WriteLine("The following lists the items before the ends have been stripped:");
        Console.WriteLine("-----------------------------------------------------------------");

        // print out the initial array of strings
        foreach ( string s in strSource )
            Console.WriteLine( s );

        Console.WriteLine();

        Console.WriteLine("The following lists the items after the ends have been stripped:");
        Console.WriteLine("----------------------------------------------------------------");

        // print out the array of strings
        foreach ( string s in strSource )
            Console.WriteLine( StripEndTags( s ) );
    }

    private static string StripEndTags( string item ) {

            // try to find a tag at the end of the line using EndsWith
            if (item.Trim().EndsWith(">")) {

                // now search for the opening tag...
                int lastLocation = item.LastIndexOf( "</" );

                // remove the identified section, if it is a valid region
                if ( lastLocation >= 0 )
                    item =  item.Substring( 0, lastLocation );
            }

    return item;
    }
}
Visual C++
using namespace System;
using namespace System::Collections;
String^ StripEndTags( String^ item )
{

   // try to find a tag at the end of the line using EndsWith
   if ( item->Trim()->EndsWith( ">" ) )
   {

      // now search for the opening tag...
      int lastLocation = item->LastIndexOf( "</" );

      // remove the identified section, if it is a valid region
      if ( lastLocation >= 0 )
            item = item->Substring( 0, lastLocation );
   }

   return item;
}

int main()
{

   // process an input file that contains html tags.
   // this sample checks for multiple tags at the end of the line, rather than simply
   // removing the last one.
   // note: HTML markup tags always end in a greater than symbol (>).
   array<String^>^strSource = {"<b>This is bold text</b>","<H1>This is large Text</H1>","<b><i><font color=green>This has multiple tags</font></i></b>","<b>This has <i>embedded</i> tags.</b>","This line simply ends with a greater than symbol, it should not be modified>"};
   Console::WriteLine( "The following lists the items before the ends have been stripped:" );
   Console::WriteLine( "-----------------------------------------------------------------" );

   // print out the initial array of strings
   IEnumerator^ myEnum1 = strSource->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      String^ s = safe_cast<String^>(myEnum1->Current);
      Console::WriteLine( s );
   }

   Console::WriteLine();
   Console::WriteLine( "The following lists the items after the ends have been stripped:" );
   Console::WriteLine( "----------------------------------------------------------------" );

   // print out the array of strings
   IEnumerator^ myEnum2 = strSource->GetEnumerator();
   while ( myEnum2->MoveNext() )
   {
      String^ s = safe_cast<String^>(myEnum2->Current);
      Console::WriteLine( StripEndTags( s ) );
   }
}

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework クラス ライブラリ
String..::.EndsWith メソッド (String)

この文字列インスタンスの末尾が、指定した文字列と一致するかどうかを判断します。

名前空間:  System
アセンブリ:  mscorlib (mscorlib.dll 内)
Visual Basic
Public Function EndsWith ( _
    value As String _
) As Boolean
C#
public bool EndsWith(
    string value
)
Visual C++
public:
bool EndsWith(
    String^ value
)
F#
member EndsWith : 
        value:string -> bool 

パラメーター

value
型: System..::.String
このインスタンスの末尾の部分文字列と比較する文字列。

戻り値

型: System..::.Boolean
このインスタンスの末尾が value と一致する場合は true。それ以外の場合は false
例外条件
ArgumentNullException

valuenullNothingnullptrnull 参照 (Visual Basic では Nothing) なので、

このメソッドは、value と、このインスタンスの末尾にある、value とまったく同じ長さの部分文字列とを比較し、両者が等しいかどうかを調べます。 等しいという結果を得るためには、value が、この同じインスタンスへの参照であるか、このインスタンスの末尾と一致している必要があります。

このメソッドは、現在のカルチャを使用して、単語 (大文字/小文字を区別し、カルチャに依存した) 比較を実行します。

呼び出し時の注意

.NET Framework で文字列を使用するためのベスト プラクティス」で説明しているように、既定値を代入する文字列比較メソッドの呼び出さず、代わりにパラメーターを明示的に指定する必要があるメソッドを呼び出すことをお勧めします。 現在のカルチャの文字列比較の規則を使用して文字列が特定の部分文字列で終了するかどうかを確認するのには、その comparisonType パラメーターの StringComparison..::.CurrentCulture 値で EndsWith(String, StringComparison) メソッド オーバーロードを呼び出します。

次の例は、行の末尾から HTML 終了タグを削除するルーチンの一部として EndsWith メソッドを使用する方法を示しています。

Visual Basic
Imports System

Public Class EndsWithTest
    Public Shared Sub Main()
        Dim strSource() As String = { "<b>This is bold text</b>", _
                    "<H1>This is large Text</H1>", _
                    "<b><i><font color = green>This has multiple tags</font></i></b>", _
                    "<b>This has <i>embedded</i> tags.</b>", _
                    "This line simply ends with a greater than symbol, it should not be modified>"}

        Console.WriteLine("The following lists the items before the ends have been stripped:")
        Console.WriteLine("-----------------------------------------------------------------")

        ' Display the initial array of strings.
        For Each s As String In  strSource
            Console.WriteLine(s)
        Next
        Console.WriteLine()

        Console.WriteLine("The following lists the items after the ends have been stripped:")
        Console.WriteLine("----------------------------------------------------------------")

        ' Display the array of strings.
        For Each s As String In strSource
            Console.WriteLine(StripEndTags(s))
        Next 
    End Sub 

    Private Shared Function StripEndTags(item As String) As String
        ' Try to find a tag at the end of the line using EndsWith.
        If item.Trim().EndsWith(">") Then
            ' now search for the opening tag...
            Dim lastLocation As Integer = item.LastIndexOf("</")
            If lastLocation >= 0 Then

                ' Remove the identified section, if it is a valid region.
                item = item.Substring(0, lastLocation)
            End If
        End If
       Return Item
    End Function 
End Class
' The example displays the following output:
'    The following lists the items before the ends have been stripped:
'    -----------------------------------------------------------------
'    <b>This is bold text</b>
'    <H1>This is large Text</H1>
'    <b><i><font color = green>This has multiple tags</font></i></b>
'    <b>This has <i>embedded</i> tags.</b>
'    This line simply ends with a greater than symbol, it should not be modified>
'    
'    The following lists the items after the ends have been stripped:
'    ----------------------------------------------------------------
'    <b>This is bold text
'    <H1>This is large Text
'    <b><i><font color = green>This has multiple tags</font></i>
'    <b>This has <i>embedded</i> tags.
'    This line simply ends with a greater than symbol, it should not be modified>
C#
using System;

public class EndsWithTest {
    public static void Main() {

        // process an input file that contains html tags.
        // this sample checks for multiple tags at the end of the line, rather than simply
        // removing the last one.
        // note: HTML markup tags always end in a greater than symbol (>).

        string [] strSource = { "<b>This is bold text</b>", "<H1>This is large Text</H1>",
                "<b><i><font color=green>This has multiple tags</font></i></b>",
                "<b>This has <i>embedded</i> tags.</b>",
                "This line simply ends with a greater than symbol, it should not be modified>" };

        Console.WriteLine("The following lists the items before the ends have been stripped:");
        Console.WriteLine("-----------------------------------------------------------------");

        // print out the initial array of strings
        foreach ( string s in strSource )
            Console.WriteLine( s );

        Console.WriteLine();

        Console.WriteLine("The following lists the items after the ends have been stripped:");
        Console.WriteLine("----------------------------------------------------------------");

        // print out the array of strings
        foreach ( string s in strSource )
            Console.WriteLine( StripEndTags( s ) );
    }

    private static string StripEndTags( string item ) {

            // try to find a tag at the end of the line using EndsWith
            if (item.Trim().EndsWith(">")) {

                // now search for the opening tag...
                int lastLocation = item.LastIndexOf( "</" );

                // remove the identified section, if it is a valid region
                if ( lastLocation >= 0 )
                    item =  item.Substring( 0, lastLocation );
            }

    return item;
    }
}
Visual C++
using namespace System;
using namespace System::Collections;
String^ StripEndTags( String^ item )
{

   // try to find a tag at the end of the line using EndsWith
   if ( item->Trim()->EndsWith( ">" ) )
   {

      // now search for the opening tag...
      int lastLocation = item->LastIndexOf( "</" );

      // remove the identified section, if it is a valid region
      if ( lastLocation >= 0 )
            item = item->Substring( 0, lastLocation );
   }

   return item;
}

int main()
{

   // process an input file that contains html tags.
   // this sample checks for multiple tags at the end of the line, rather than simply
   // removing the last one.
   // note: HTML markup tags always end in a greater than symbol (>).
   array<String^>^strSource = {"<b>This is bold text</b>","<H1>This is large Text</H1>","<b><i><font color=green>This has multiple tags</font></i></b>","<b>This has <i>embedded</i> tags.</b>","This line simply ends with a greater than symbol, it should not be modified>"};
   Console::WriteLine( "The following lists the items before the ends have been stripped:" );
   Console::WriteLine( "-----------------------------------------------------------------" );

   // print out the initial array of strings
   IEnumerator^ myEnum1 = strSource->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      String^ s = safe_cast<String^>(myEnum1->Current);
      Console::WriteLine( s );
   }

   Console::WriteLine();
   Console::WriteLine( "The following lists the items after the ends have been stripped:" );
   Console::WriteLine( "----------------------------------------------------------------" );

   // print out the array of strings
   IEnumerator^ myEnum2 = strSource->GetEnumerator();
   while ( myEnum2->MoveNext() )
   {
      String^ s = safe_cast<String^>(myEnum2->Current);
      Console::WriteLine( StripEndTags( s ) );
   }
}

.NET Framework

サポート対象: 4、3.5、3.0、2.0、1.1、1.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 (Server Core はサポート対象外), Windows Server 2008 R2 (SP1 以降で Server Core をサポート), Windows Server 2003 SP2

.NET Framework では、各プラットフォームのすべてのバージョンはサポートしていません。 サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2012 Microsoft. All rights reserved. 使用条件 | 商標 | プライバシー
Page view tracker