Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
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
Assemblies:   System.Globalization (in System.Globalization.dll)
  mscorlib (in mscorlib.dll)

'Declaration
Public Overridable Function IsSuffix ( _
	source As String, _
	suffix As String, _
	options As CompareOptions _
) As Boolean

Parameters

source
Type: System.String

The string to search in.

suffix
Type: System.String

The string to compare with the end of source.

options
Type: System.Globalization.CompareOptions

A value that defines how source and suffix should be compared. options is either the enumeration 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

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

ExceptionCondition
ArgumentNullException

source is Nothing.

-or-

suffix is Nothing.

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.

NoteNote

When possible, you should call string comparison methods that have a parameter of type CompareOptions to specify the kind of comparison expected. As a general rule, use linguistic options (using the current culture) for comparing strings displayed in the user interface and specify CompareOptions.Ordinal or CompareOptions.OrdinalIgnoreCase for security comparisons.

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

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft