Pages

Wednesday, July 6, 2011

Extract Digits nd Char out of string with Regular expression

Extract Digits out of string with Regular expression

public string ExtractNum(string xnumberx)
{
        string[] numbers = Regex.Split(xnumberx, @"\D+");
        string RetNum = "";
foreach (string value in numbers)
   {
      if (!string.IsNullOrEmpty(value))
             {
                int i = int.Parse(value);
                RetNum = RetNum + i;
             }
    }
       return RetNum;
}

Extract Char out of string with Regular expression

public string RetString(string strspcex)
   {
      return Regex.Replace(strspcex, @"\d", "");
   }

No comments:

Post a Comment