Search
Learn
Share

Test if StringBuilder value StartsWith a string in C#

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

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

var start = sb.ToString(0, test.Length);
return start.Equals(test);
}