title: Convert numbers in string to English word format
body: <p>I have a C# method that converts integer numbers into their English word counterparts; however, how can I implement this so it'll work with a string.</p>
  
  <p>For example, if I have the following string:</p>
  
  <p><em>There was a dog. The dog ate 1000 bones. After eating, he was very sleepy. He slept for 12 hours.</em></p>
  
  <p>I want it to parse it and return:</p>
  
  <p><em>There was a dog. The dog ate one thousand bones. After eating, he was very sleepy. He slept for twelve hours.</em></p>
  
  <p>How would I go by taking the numbers out of the sentence, and using the conversion method (below)?</p>
  
  <pre><code>public static string NumberToWords(int number)
  {
      if (number == 0)
          return "zero";
  
      if (number &lt; 0)
          return "minus " + NumberToWords(Math.Abs(number));
  
      string words = "";
  
      if ((number / 1000000) &gt; 0)
      {
          words += NumberToWords(number / 1000000) + " million ";
          number %= 1000000;
      }
  
      if ((number / 1000) &gt; 0)
      {
          words += NumberToWords(number / 1000) + " thousand ";
          number %= 1000;
      }
  
      if ((number / 100) &gt; 0)
      {
          words += NumberToWords(number / 100) + " hundred ";
          number %= 100;
      }
  
      if (number &gt; 0)
      {
          if (words != "")
              words += "and ";
  
          var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
          var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
  
          if (number &lt; 20)
              words += unitsMap[number];
          else
          {
              words += tensMap[number / 10];
              if ((number % 10) &gt; 0)
                  words += "-" + unitsMap[number % 10];
          }
      }
  
      return words;
  }
  </code></pre>
  
  <p>I tried doing a foreach, like this, but it didn't work...</p>
  
  <pre><code>var matches = Regex.Matches(myString, "[0-9]+");
  foreach(var match in matches)
  {
     NumberToWords(match);
  }
  </code></pre>