Thursday, 8 July 2010

GET NUMBER FROM STRING

  1. private int GetNumber(string str)
  2. {
  3. int length = str.Length;
  4. string output = String.Empty;
  5. int test = 0;
  6. bool err = false;
  7. for(int i=0;i<=length;i++)
  8. {
  9. try
  10. {
  11. test = Convert.ToInt32(str.Substring(i,1));
  12. }
  13. catch
  14. {
  15. err = true;
  16. }
  17. if (!err)
  18. output += str.Substring(i,1);
  19. else
  20. break;
  21. }
  22. return Convert.ToInt32(output);
  23. }

No comments:

Post a Comment