Advertisement
Guest User

FE

a guest
Dec 4th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. //Rextester.Program.Main is the entry point for your code. Don't change it.
  2. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Rextester
  10. {
  11.     public class Program
  12.     {
  13.         public static void Main(string[] args)
  14.         {
  15.             int[] numbers = SplitInt(12345);
  16.  
  17.             foreach (int number in numbers)
  18.                 Console.Write(number + " ");
  19.             // 1 2 3 4 5
  20.         }
  21.        
  22.         private static int[] SplitInt(int number)
  23.         {
  24.             string num = number.ToString();
  25.             int[] output = new int[num.Length];
  26.        
  27.             for (int i = 0; i < num.Length; i++)
  28.                 output[i] = (int)Char.GetNumericValue(num[i]);
  29.        
  30.             return output;
  31.             /*
  32.                 (int)Char.GetNumericValue(num[i]); Does The Trick
  33.                
  34.                 string num = "text";
  35.                 num  is string
  36.                 num[0] is char
  37.                
  38.                 Converting Chars will actually give you the ASCII code
  39.                 1 = 49
  40.                 2 = 50
  41.                 3 = 51
  42.                 4 = 52
  43.                 5 = 53
  44.             */
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement