Last active
September 13, 2021 10:05
-
-
Save mirmostafa/f93b6e41cc3c494bec37fbcc4c802275 to your computer and use it in GitHub Desktop.
The fastest way to add a string to another.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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