Search
Learn
Share

Test if StringBuilder value EndsWith a string in C#

Published by Profile Image DevDashboard on 25 July, 2017
22 views
Add this extension method to use EndsWith on a Stringbuilder:

public static bool EndsWith(this StringBuilder sb, string test)
{
if (sb.Length < test.Length) return false;

var end = sb.ToString(sb.Length - test.Length, test.Length);
return end.Equals(test);
}