String to int array
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
using System; using System.Linq; class Program { static void Main(string[] args) { //this line create a string variable. string stringOfInteger = "1,5,10,15,,,20,25,30"; Console.WriteLine("string of ip integer value............"); Console.WriteLine(stringOfInteger); //split string and create an integer data type array. int[] intArray = stringOfInteger .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse).ToArray(); Console.WriteLine("elements of int array............"); foreach (int x in intArray) { Console.WriteLine(x); } Console.ReadLine(); } } |
Output: