CompareInfo::IsSuffix Method (String, String)
Determines whether the specified source string ends with the specified suffix.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- source
- Type: System::String
The string to search in.
- suffix
- Type: System::String
The string to compare with the end of source.
Return Value
Type: System::Booleantrue if the length of suffix is less than or equal to the length of source and source ends with suffix; otherwise, false.
| Exception | Condition |
|---|---|
| ArgumentNullException | source is nullptr. -or- suffix is nullptr. |
Every string starts and ends with an empty substring (""); therefore, if suffix is an empty string, this method returns true.
Note |
|---|
When possible, the application should use string comparison methods that accept a CompareOptions value to specify the kind of comparison expected. As a general rule, user-facing comparisons are best served by the use of linguistic options (using the current culture), while security comparisons should specify Ordinal or OrdinalIgnoreCase. |
The following code example determines whether a string is the prefix or suffix of another string.
using namespace System; using namespace System::Globalization; int 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; // Determines whether myXfix is a prefix of S"calle" and S"llegar". Console::WriteLine( "IsPrefix( {0}, {1}) : {2}", myStr1, myXfix, myComp->IsPrefix( myStr1, myXfix ) ); Console::WriteLine( "IsPrefix( {0}, {1}) : {2}", myStr2, myXfix, myComp->IsPrefix( myStr2, myXfix ) ); // Determines whether myXfix is a suffix of S"calle" and S"llegar". Console::WriteLine( "IsSuffix( {0}, {1}) : {2}", myStr1, myXfix, myComp->IsSuffix( myStr1, myXfix ) ); Console::WriteLine( "IsSuffix( {0}, {1}) : {2}", myStr2, myXfix, myComp->IsSuffix( myStr2, myXfix ) ); } /* This code produces the following output. IsPrefix(calle, lle) : False IsPrefix(llegar, lle) : True IsSuffix(calle, lle) : True IsSuffix(llegar, lle) : False */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), 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.
Note