Return Value

This method compares value to the substring at the end of this instance that is the same length as value, and returns an indication whether they are equal. To be equal, value must be a reference to this same instance, or match the end of this instance.

This method performs a word (case-sensitive and culture-sensitive) comparison using the current culture.

using System;
publicclass EndsWithTest {
publicstaticvoid Main() {
// process an input file that contains html tags.// this sample checks for multiple tags at the end of the line, rather than simply// removing the last one.// note: HTML markup tags always end in a greater than symbol (>).string [] strSource = { "<b>This is bold text</b>", "<H1>This is large Text</H1>",
"<b><i><font color=green>This has multiple tags</font></i></b>",
"<b>This has <i>embedded</i> tags.</b>",
"This line simply ends with a greater than symbol, it should not be modified>" };
Console.WriteLine("The following lists the items before the ends have been stripped:");
Console.WriteLine("-----------------------------------------------------------------");
// print out the initial array of stringsforeach ( string s in strSource )
Console.WriteLine( s );
Console.WriteLine();
Console.WriteLine("The following lists the items after the ends have been stripped:");
Console.WriteLine("----------------------------------------------------------------");
// print out the array of stringsforeach ( string s in strSource )
Console.WriteLine( StripEndTags( s ) );
}
privatestaticstring StripEndTags( string item ) {
// try to find a tag at the end of the line using EndsWithif (item.Trim().EndsWith(">")) {
// now search for the opening tag...int lastLocation = item.LastIndexOf( "</" );
// remove the identified section, if it is a valid regionif ( lastLocation >= 0 )
item = item.Substring( 0, lastLocation );
}
return item;
}
}