Export (0) Print
Expand All

CompareInfo.IsSuffix Method (String, String, CompareOptions)

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

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

public virtual bool IsSuffix (
	string source,
	string suffix,
	CompareOptions options
)
public boolean IsSuffix (
	String source, 
	String suffix, 
	CompareOptions options
)
public function IsSuffix (
	source : String, 
	suffix : String, 
	options : CompareOptions
) : boolean

Parameters

source

The string to search in.

suffix

The string to compare with the end of source.

options

The CompareOptions value that defines how source and suffix should be compared. options is either the value Ordinal used by itself, or the bitwise combination of one or more of the following values: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth, and IgnoreKanaType.

Return Value

true if the length of suffix is less than or equal to the length of source and source ends with suffix; otherwise, false.

Exception typeCondition

ArgumentNullException

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

-or-

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

ArgumentException

options contains an invalid CompareOptions value.

Every string starts and ends with an empty substring (""); therefore, if suffix is an empty string, this method returns true.

The CompareOptions.StringSort value is not valid for this method.

The following code example determines whether a string is the prefix or suffix of another string using CompareOptions.

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

*/

import System.* ;
import System.Globalization.* ;

public class SamplesCompareInfo
{
    public static void main(String[] args)
    {
        // Defines the strings to compare.
        String myStr1 = "calle";
        String myStr2 = "llegar";
        String myXfix = "LLE";

        // Uses the CompareInfo property of the InvariantCulture.
        CompareInfo myComp = 
            CultureInfo.get_InvariantCulture().get_CompareInfo();

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

        Console.WriteLine("IsPrefix \"{0}\", \"{1}\"", myStr2, myXfix);
        Console.WriteLine("   With no CompareOptions            : {0}", 
            System.Convert.ToString(myComp.IsPrefix(myStr2, myXfix)));
        Console.WriteLine("   With None                         : {0}", 
            System.Convert.ToString(myComp.IsPrefix(myStr2, myXfix, 
            CompareOptions.None)));
        Console.WriteLine("   With Ordinal                      : {0}", 
            System.Convert.ToString(myComp.IsPrefix(myStr2, myXfix, 
            CompareOptions.Ordinal)));
        Console.WriteLine("   With IgnoreCase                   : {0}",
            System.Convert.ToString(myComp.IsPrefix(myStr2, myXfix, 
            CompareOptions.IgnoreCase)));
    } //main 
} //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
*/

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft