Advertisement
Methods | Description |
---|---|
EndsWith(String) | This method determines whether the ending of the invoked String matches with String object passed to this method. |
EndssWith(String, StringComparison) | This method determines whether the ending of the invoked String matches with String object passed to this method, when compared using specified StringComparison. |
EndsWith(String, Boolean, CultureInfo) | This method determines whether the ending of the invoked String matches with String object passed to this method, when compared using specified CultureInfo. |
//C# EndsWith() method of String.
using System;
class StringEndsWith
{
public static void Main()
{
String str1 = "A Blue Moon";
Console.WriteLine("String is: " + str1);
bool boo1 = str1.EndsWith("Moon");
Console.WriteLine("Does "+ str1 + " ends with Moon ? "+ boo1);
boo1 = str1.EndsWith("on");
Console.WriteLine("Does "+ str1 + " ends with on ? "+ boo1);
boo1 = str1.EndsWith("Moons");
Console.WriteLine("Does "+ str1 + " ends with Moons ? "+ boo1);
boo1 = str1.EndsWith("A Blue");
Console.WriteLine("Does "+ str1 + " ends with A Blue ? "+ boo1);
}
}
String is: A Blue Moon
Does A Blue Moon ends with Moon ? True
Does A Blue Moon ends with on ? True
Does A Blue Moon ends with Moons ? False
Does A Blue Moon ends with A Blue ? False
//C# EndsWith() method of String.
using System;
class StringEndsWithEx
{
public static void Main()
{
String str1 = "A Mango Tree";
Console.WriteLine("String is: " + str1);
bool boo1 = str1.EndsWith("Tree");
Console.WriteLine("Does "+ str1 + " ends with Tree ? "+ boo1);
boo1 = str1.EndsWith("tree");
Console.WriteLine("Does "+ str1 + " ends with tree ? "+ boo1);
boo1 = str1.EndsWith("mango Tree");
Console.WriteLine("Does "+ str1 + " ends with mango Tree ? "+ boo1);
}
}
String is: A Mango Tree
Does A Mango Tree ends with Tree ? True
Does A Mango Tree ends with tree ? False
Does A Mango Tree ends with mango Tree ? False
Advertisement
Fields of StringComparison | Value | Description |
---|---|---|
CurrentCulture | 0 | Compares String objects using culture-sensitive sort rules and current culture. |
CurrentCultureIgnoreCase | 1 | Compares String objects using culture-sensitive sort rules and current culture, while ignoring the case of the String objects being compared. |
InvariantCulture | 2 | Compares String objects using culture-sensitive sort rules and invariant culture. |
InvariantCultureIgnoreCase | 3 | Compares String objects using culture-sensitive sort rules and invariant culture, while ignoring the case of the String objects being compared. |
Ordinal | 4 | Compares String objects using ordinal(binary) sort rules. |
OrdinalIgnoreCase | 5 | Compares String objects using ordinal(binary) sort rules, while ignoring the case of the String objects being compared. |
//C# Example of EndsWith(String, StringComparison) method of String.
using System;
class StringEndsWith
{
public static void Main()
{
String str1 = "A kind heart";
Console.WriteLine("String is: " + str1);
//String comparison made using StringComparison.CurrentCulture
Console.WriteLine("String comparison by StringComparison.CurrentCulture:");
bool boo1 = str1.EndsWith("heart", StringComparison.CurrentCulture);
Console.WriteLine("Does "+ str1 + " ends with heart ? "+ boo1);
boo1 = str1.EndsWith("arts", StringComparison.CurrentCulture);
Console.WriteLine("Does "+ str1 + " ends with arts ? "+ boo1);
//String comparison made using StringComparison.CurrentCultureIgnoreCase
Console.WriteLine("String comparison by StringComparison.CurrentCultureIgnoreCase:");
boo1 = str1.EndsWith("ART", StringComparison.CurrentCultureIgnoreCase);
Console.WriteLine("Does "+ str1 + " ends with ART ? "+ boo1);
boo1 = str1.EndsWith("hearts", StringComparison.CurrentCultureIgnoreCase);
Console.WriteLine("Does "+ str1 + " ends with hearts ? "+ boo1);
//String comparison made using StringComparison.InvariantCulture
Console.WriteLine("String comparison by StringComparison.InvariantCulture: ");
boo1 = str1.EndsWith("heart", StringComparison.InvariantCulture);
Console.WriteLine("Does "+ str1 + " ends with heart ? "+ boo1);
boo1 = str1.EndsWith("arts", StringComparison.InvariantCulture);
Console.WriteLine("Does "+ str1 + " ends with arts ? "+ boo1);
//String comparison made using StringComparison.InvariantCultureIgnoreCase
Console.WriteLine("String comparison by StringComparison.InvariantCultureIgnoreCase: ");
boo1 = str1.EndsWith("ART", StringComparison.InvariantCultureIgnoreCase);
Console.WriteLine("Does "+ str1 + " ends with ART ? "+ boo1);
boo1 = str1.EndsWith("hearts", StringComparison.CurrentCultureIgnoreCase);
Console.WriteLine("Does "+ str1 + " ends with hearts ? "+ boo1);
//String comparison made using StringComparison.Ordinal
Console.WriteLine("String comparison by StringComparison.Ordinal: ");
boo1 = str1.EndsWith("heart", StringComparison.Ordinal);
Console.WriteLine("Does "+ str1 + " ends with heart ? "+ boo1);
boo1 = str1.EndsWith("arts", StringComparison.Ordinal);
Console.WriteLine("Does "+ str1 + " ends with arts ? "+ boo1);
//String comparison made using StringComparison.OrdinalIgnoreCase
Console.WriteLine("String comparison by StringComparison.OrdinalIgnoreCase: ");
boo1 = str1.EndsWith("ART", StringComparison.OrdinalIgnoreCase);
Console.WriteLine("Does "+ str1 + " ends with ART ? "+ boo1);
boo1 = str1.EndsWith("hearts", StringComparison.CurrentCultureIgnoreCase);
Console.WriteLine("Does "+ str1 + " ends with hearts ? "+ boo1);
}
}
String is: A kind heart
String comparison by StringComparison.CurrentCulture:
Does A kind heart ends with heart ? True
Does A kind heart ends with arts ? False
String comparison by StringComparison.CurrentCultureIgnoreCase:
Does A kind heart ends with ART ? True
Does A kind heart ends with hearts ? False
String comparison by StringComparison.InvariantCulture:
Does A kind heart ends with heart ? True
Does A kind heart ends with arts ? False
String comparison by StringComparison.InvariantCultureIgnoreCase:
Does A kind heart ends with ART ? True
Does A kind heart ends with hearts ? False
String comparison by StringComparison.Ordinal:
Does A kind heart ends with heart ? True
Does A kind heart ends with arts ? False
String comparison by StringComparison.OrdinalIgnoreCase:
Does A kind heart ends with ART ? True
Does A kind heart ends with hearts ? False
//C# Example of EndsWith(String, Boolean, CultureInfo)
using System;
using System.Globalization;
class StringUpper
{
public static void Main()
{
//Extracting and printing the current culture of our system
CultureInfo current = CultureInfo.CurrentUICulture;
Console.WriteLine("The current UI culture of our system is {0}", current.Name);
//Creating a String object and printing it
String str1 = "Share Smiles";
Console.WriteLine("String is: " + str1);
//Creating an object of CultureInfo class based on the English-US culture
CultureInfo ci1 = new CultureInfo("en-us", false);
//Creating an object of CultureInfo class based on the Turkish-Turkey culture
CultureInfo ci2 = new CultureInfo("tk-TR", false);
//Creating an object of CultureInfo class based on the Turkish-Turkey culture
CultureInfo ci3 = new CultureInfo("fr-FR", false);
//Comparing String objects according to English-United States culture
Console.WriteLine("Based on English-US culture, does " + str1 + " ends with Share ? " + str1.EndsWith("Smiles", false, ci1));
//Comparing String objects according to Turkish-Turkey culture
Console.WriteLine("based on Turkish-Turkish culture, does " + str1 + " ends with Share ? " + str1.EndsWith("Smiles", false, ci2));
//Comparing String objects according to French-France culture
Console.WriteLine("Based on French-France culture, does " + str1 + " ends with Share ?" + str1.EndsWith("Smiles", false, ci3));
}
}
The current UI culture of our system is en-US
String is: Share Smiles
Based on English-US culture, does Share Smiles ends with Share ? True
based on Turkish-Turkish culture, does Share Smiles ends with Share ? True
Based on French-France culture, does Share Smiles ends with Share ?True
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement