Skip to content

Instantly share code, notes, and snippets.

@lexuschert
Last active September 5, 2021 09:26
Show Gist options
  • Save lexuschert/35003ad944abc9a581fc66b066397005 to your computer and use it in GitHub Desktop.
Save lexuschert/35003ad944abc9a581fc66b066397005 to your computer and use it in GitHub Desktop.
Faster mask for string
/// Faster mask for string
/// Example: CreateMask("Password123")
/// Return: Pas********
///
/// https://www.youtube.com/watch?v=Kd8oNLeRc2c
///
public static string CreateMask(string stringValue) =>
string.Create(
stringValue.Length,
stringValue,
(span, value) => {
value.AsSpan().CopyTo(span);
span[3..].Fill('*')
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment