Export (0) Print
Expand All

CompareInfo.IsSuffix Method

Determines whether a string ends with a specific suffix.

Overload List

Determines whether the specified source string ends with the specified suffix.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function IsSuffix(String, String) As Boolean
[C#] public virtual bool IsSuffix(string, string);
[C++] public: virtual bool IsSuffix(String*, String*);
[JScript] public function IsSuffix(String, String) : Boolean;

Determines whether the specified source string ends with the specified suffix using the specified CompareOptions value.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function IsSuffix(String, String, CompareOptions) As Boolean
[C#] public virtual bool IsSuffix(string, string, CompareOptions);
[C++] public: virtual bool IsSuffix(String*, String*, CompareOptions);
[JScript] public function IsSuffix(String, String, CompareOptions) : Boolean;

Example

[Visual Basic, C#, C++] The following code example determines whether a string is the prefix or suffix of another string using CompareOptions.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of IsSuffix. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Defines the strings to compare.
      Dim myStr1 As [String] = "calle"
      Dim myStr2 As [String] = "llegar"
      Dim myXfix As [String] = "LLE"

      ' Uses the CompareInfo property of the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      Console.WriteLine("IsSuffix ""{0}"", ""{1}""", myStr1, myXfix)
      Console.WriteLine("   With no CompareOptions            : {0}", myComp.IsSuffix(myStr1, myXfix))
      Console.WriteLine("   With None                         : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.None))
      Console.WriteLine("   With Ordinal                      : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.Ordinal))
      Console.WriteLine("   With IgnoreCase                   : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.IgnoreCase))

      Console.WriteLine("IsPrefix ""{0}"", ""{1}""", myStr2, myXfix)
      Console.WriteLine("   With no CompareOptions            : {0}", myComp.IsPrefix(myStr2, myXfix))
      Console.WriteLine("   With None                         : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.None))
      Console.WriteLine("   With Ordinal                      : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.Ordinal))
      Console.WriteLine("   With IgnoreCase                   : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.IgnoreCase))

   End Sub 'Main 

End Class 'SamplesCompareInfo


'This code produces the following output.
'
'IsSuffix "calle", "LLE"
'   With no CompareOptions            : False
'   With None                         : False
'   With Ordinal                      : False
'   With IgnoreCase                   : True
'IsPrefix "llegar", "LLE"
'   With no CompareOptions            : False
'   With None                         : False
'   With Ordinal                      : False
'   With IgnoreCase                   : True


[C#] 
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Defines the strings to compare.
      String myStr1 = "calle";
      String myStr2 = "llegar";
      String myXfix = "LLE";

      // Uses the CompareInfo property of the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      Console.WriteLine( "IsSuffix \"{0}\", \"{1}\"", myStr1, myXfix );
      Console.WriteLine( "   With no CompareOptions            : {0}", myComp.IsSuffix( myStr1, myXfix ) );
      Console.WriteLine( "   With None                         : {0}", myComp.IsSuffix( myStr1, myXfix, CompareOptions.None ) );
      Console.WriteLine( "   With Ordinal                      : {0}", myComp.IsSuffix( myStr1, myXfix, CompareOptions.Ordinal ) );
      Console.WriteLine( "   With IgnoreCase                   : {0}", myComp.IsSuffix( myStr1, myXfix, CompareOptions.IgnoreCase ) );

      Console.WriteLine( "IsPrefix \"{0}\", \"{1}\"", myStr2, myXfix );
      Console.WriteLine( "   With no CompareOptions            : {0}", myComp.IsPrefix( myStr2, myXfix ) );
      Console.WriteLine( "   With None                         : {0}", myComp.IsPrefix( myStr2, myXfix, CompareOptions.None ) );
      Console.WriteLine( "   With Ordinal                      : {0}", myComp.IsPrefix( myStr2, myXfix, CompareOptions.Ordinal ) );
      Console.WriteLine( "   With IgnoreCase                   : {0}", myComp.IsPrefix( myStr2, myXfix, CompareOptions.IgnoreCase ) );

   }

}


/*
This code produces the following output.

IsSuffix "calle", "LLE"
   With no CompareOptions            : False
   With None                         : False
   With Ordinal                      : False
   With IgnoreCase                   : True
IsPrefix "llegar", "LLE"
   With no CompareOptions            : False
   With None                         : False
   With Ordinal                      : False
   With IgnoreCase                   : True

*/

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

int main() {
   // Defines the strings to compare.
   String*  myStr1 = S"calle";
   String*  myStr2 = S"llegar";
   String*  myXfix = S"LLE";

   // Uses the CompareInfo property of the InvariantCulture.
   CompareInfo*  myComp = CultureInfo::InvariantCulture->CompareInfo;

   Console::WriteLine(S"IsSuffix \"{0}\", \"{1}\"", myStr1, myXfix);
      Console::WriteLine(S"   With no CompareOptions            : {0}", 
         __box(myComp->IsSuffix(myStr1, myXfix)));
   Console::WriteLine(S"   With None                         : {0}", 
      __box(myComp->IsSuffix(myStr1, myXfix, CompareOptions::None)));
   Console::WriteLine(S"   With Ordinal                      : {0}", 
      __box(myComp->IsSuffix(myStr1, myXfix, CompareOptions::Ordinal)));
   Console::WriteLine(S"   With IgnoreCase                   : {0}", 
      __box(myComp->IsSuffix(myStr1, myXfix, CompareOptions::IgnoreCase)));

   Console::WriteLine(S"IsPrefix \"{0}\", \"{1}\"", myStr2, myXfix);
      Console::WriteLine(S"   With no CompareOptions            : {0}", 
         __box(myComp->IsPrefix(myStr2, myXfix)));
   Console::WriteLine(S"   With None                         : {0}", 
      __box(myComp->IsPrefix(myStr2, myXfix, CompareOptions::None)));
   Console::WriteLine(S"   With Ordinal                      : {0}", 
      __box(myComp->IsPrefix(myStr2, myXfix, CompareOptions::Ordinal)));
   Console::WriteLine(S"   With IgnoreCase                   : {0}", 
      __box(myComp->IsPrefix(myStr2, myXfix, CompareOptions::IgnoreCase)));
}

/*
This code produces the following output.

IsSuffix "calle", "LLE"
   With no CompareOptions            : False
   With None                         : False
   With Ordinal                      : False
   With IgnoreCase                   : True
IsPrefix "llegar", "LLE"
   With no CompareOptions            : False
   With None                         : False
   With Ordinal                      : False
   With IgnoreCase                   : True
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

CompareInfo Class | CompareInfo Members | System.Globalization Namespace

Show:
© 2014 Microsoft