65.9K
CodeProject is changing. Read more.
Home

StringBuilder Extensions

starIconstarIconstarIconstarIconstarIcon

5.00/5 (7 votes)

Nov 30, 2010

CPOL
viewsIcon

12648

A note about StringBuilder Extensions

Forgive me for sounding a little pedantic, but wouldn't you be able to use the LTrim and RTrim functions within the Trim function? (You'll have to forgive my syntax, I'm more of a Delphi guy myself). "Re-writing" the same code in separate places tends to cause issues when you need to update it, or at least that's what I've found when working on my code Smile | :) .

/// <summary>
/// Trim spaces around string
/// </summary>
/// <param name="sb"></param>
/// <returns></returns>
public static StringBuilder Trim(this StringBuilder sb)
{
    sb = LTrim(sb);
    sb = RTrim(sb);
    return sb;
}

Thanks,
Glen Vlotman