I have a requirement to find and extract a number contained within a string.
For example, from these strings:
string test = \"1 test\" string test1 =
static string GetdigitFromString(string str) { char[] refArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; char[] inputArray = str.ToCharArray(); string ext = string.Empty; foreach (char item in inputArray) { if (refArray.Contains(item)) { ext += item.ToString(); } } return ext; }