Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rextester.Program.Main is the entry point for your code. Don't change it.
- //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Rextester
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- int[] numbers = SplitInt(12345);
- foreach (int number in numbers)
- Console.Write(number + " ");
- // 1 2 3 4 5
- }
- private static int[] SplitInt(int number)
- {
- string num = number.ToString();
- int[] output = new int[num.Length];
- for (int i = 0; i < num.Length; i++)
- output[i] = (int)Char.GetNumericValue(num[i]);
- return output;
- /*
- (int)Char.GetNumericValue(num[i]); Does The Trick
- string num = "text";
- num is string
- num[0] is char
- Converting Chars will actually give you the ASCII code
- 1 = 49
- 2 = 50
- 3 = 51
- 4 = 52
- 5 = 53
- */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement