Created
August 19, 2022 05:22
-
-
Save danzuep/698fd09d1b6b0baf1b40a1cc0e7b8a34 to your computer and use it in GitHub Desktop.
This file contains 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 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