// This example demonstrates the // System.String.EndsWith(String, StringComparison) method. using namespace System; using namespace System::Threading; void Test(String^ testString, String^ searchString, StringComparison comparison) { String^ resultFormat = "\"{0}\" {1} with \"{2}\"."; String^ resultString = "does not end"; if (testString->EndsWith(searchString, comparison)) { resultString = "ends"; } Console::WriteLine(resultFormat, testString, resultString, searchString); } int main() { String^ introMessage = "Determine whether a string ends with another string, " + "using\ndifferent values of StringComparison."; array<StringComparison>^ comparisonValues = { StringComparison::CurrentCulture, StringComparison::CurrentCultureIgnoreCase, StringComparison::InvariantCulture, StringComparison::InvariantCultureIgnoreCase, StringComparison::Ordinal, StringComparison::OrdinalIgnoreCase}; Console::Clear(); Console::WriteLine(introMessage); // Display the current culture because the culture-specific comparisons // can produce different results with different cultures. Console::WriteLine("The current culture is {0}.\n", Thread::CurrentThread->CurrentCulture->Name); // Perform two tests for each StringComparison for each (StringComparison stringCmp in comparisonValues) { Console::WriteLine("StringComparison.{0}:", stringCmp); Test("abcXYZ", "XYZ", stringCmp); Test("abcXYZ", "xyz", stringCmp); Console::WriteLine(); } }