Skip to content

Instantly share code, notes, and snippets.

@mirmostafa
Last active September 13, 2021 10:05
Show Gist options
  • Select an option

  • Save mirmostafa/f93b6e41cc3c494bec37fbcc4c802275 to your computer and use it in GitHub Desktop.

Select an option

Save mirmostafa/f93b6e41cc3c494bec37fbcc4c802275 to your computer and use it in GitHub Desktop.
The fastest way to add a string to another.
public static string? Add(this string? s, int count, char add = ' ', bool before = false)
=> string.Create(s?.Length ?? 0, s, (span, value) =>
{
value.AsSpan().CopyTo(span);
(before ? span[..count] : span[count..]).Fill(add);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment