Advertisement
Guest User

string to ints

a guest
Jan 27th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. Console.WriteLine("Please enter a four digit number that does not begin with a zero");
  2. string nStr;
  3.  
  4. do
  5. {
  6. nStr = Console.ReadLine();
  7. if (nStr.Length != 4 || !Regex.IsMatch(nStr, @"^\d+$") || Regex.IsMatch(nStr, @"^0")) //Ask for a correct number until all three conditions are met
  8. {
  9. Console.WriteLine("Please enter a four digit number that does not begin with a zero");
  10. }
  11. else
  12. {
  13. break;
  14. }
  15. } while (true);
  16.  
  17. char[] nArr = nStr.ToCharArray();
  18. int a = int.Parse(nStr[0].ToString());
  19. int b = int.Parse(nStr[1].ToString());
  20. int c = int.Parse(nStr[2].ToString());
  21. int d = int.Parse(nStr[3].ToString());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement