Write a C# Sharp program to determine whether a string ends with a particular substring
- برمجة سي شارب
- برمجة
- 2021-05-30
- ahmadghneem
الأجوبة
using System;
using System.Threading;
class Example43
{
public static void Main()
{
string str = "Determine whether a string ends with another string, " +
"using\n different values of StringComparison.";
StringComparison[] scValues = {
StringComparison.CurrentCulture,
StringComparison.CurrentCultureIgnoreCase,
StringComparison.InvariantCulture,
StringComparison.InvariantCultureIgnoreCase,
StringComparison.Ordinal,
StringComparison.OrdinalIgnoreCase };
//
Console.Clear();
Console.WriteLine(str);
// 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);
// Determine whether three versions of the letter I are equal to each other.
foreach (StringComparison sc in scValues)
{
Console.WriteLine("StringComparison.{0}:", sc);
Test("xyzPQR", "PQR", sc);
Test("xyzPQR", "PQR", sc);
Console.WriteLine();
}
}
protected static void Test(string x, string y, StringComparison comparison)
{
string resultFmt = ""{0}" {1} with "{2}".";
string result = "does not end";
//
if (x.EndsWith(y, comparison))
result = "ends";
Console.WriteLine(resultFmt, x, result, y);
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال