Skip to content

Instantly share code, notes, and snippets.

@danzuep
Created August 19, 2022 05:22
Show Gist options
  • Save danzuep/698fd09d1b6b0baf1b40a1cc0e7b8a34 to your computer and use it in GitHub Desktop.
Save danzuep/698fd09d1b6b0baf1b40a1cc0e7b8a34 to your computer and use it in GitHub Desktop.
public class DigitsOnly
{
public static string Get(string text)
{
string result = string.Empty;
if (!string.IsNullOrWhiteSpace(text))
{
var sb = new StringBuilder(text.Length);
for (int i = 0; i < text.Length; i++)
if (text[i] >= '0' && text[i] <= '9')
sb.Append(text[i]);
result = sb.ToString();
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment