Trim ending whitespaces on timespan pretty print

This commit is contained in:
Deukhoofd 2018-08-13 18:50:50 +02:00
parent b2e3b3dec8
commit 7a9c6cec16
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 17 additions and 0 deletions

View File

@ -13,5 +13,20 @@ namespace DeukBot4.Utilities
} }
return sb.ToString(); return sb.ToString();
} }
public static StringBuilder TrimEnd(this StringBuilder sb)
{
if (sb == null || sb.Length == 0) return sb;
int i = sb.Length - 1;
for (; i >= 0; i--)
if (!char.IsWhiteSpace(sb[i]))
break;
if (i < sb.Length - 1)
sb.Length = i + 1;
return sb;
}
} }
} }

View File

@ -40,8 +40,10 @@ namespace DeukBot4.Utilities
sb.AppendFormat("{0} hour{1} ", span.Hours, span.Hours > 1 ? "s" : String.Empty); sb.AppendFormat("{0} hour{1} ", span.Hours, span.Hours > 1 ? "s" : String.Empty);
if (span.Minutes > 0) if (span.Minutes > 0)
sb.AppendFormat("{0} minute{1} ", span.Minutes, span.Minutes > 1 ? "s" : String.Empty); sb.AppendFormat("{0} minute{1} ", span.Minutes, span.Minutes > 1 ? "s" : String.Empty);
sb.TrimEnd();
return sb.ToString(); return sb.ToString();
} }
} }
} }