Split String Without Using Split Method

Today a person posted a question in forum to split a string without using any build function and display a string using index. I am posting this programe in blog for all users whoever need this logics in feature.
  1. using System;  
  2. using System.Collections;  
  3. using System.Collections.Generic;  
  4. using System.Linq;  
  5. using System.Text;  
  6. using System.Threading.Tasks;  
  7.   
  8. namespace SplitStringWithoutUsingSplitMethod  
  9. {  
  10.     class Program  
  11.     {  
  12.         static void Main(string[] args)  
  13.         {  
  14.   
  15.             string str = "This,is,C#,Corner,Website";  
  16.             ArrayList arrayList = new ArrayList();  
  17.             string Temp = "";  
  18.             for (int i = 0; i < str.Length; i++)  
  19.             {  
  20.   
  21.                 if (str[i] != ',')  
  22.                 {  
  23.                     Temp = Temp + str[i];  
  24.                     continue;  
  25.                 }  
  26.   
  27.   
  28.                 arrayList.Add(Temp);  
  29.                 Temp = "";  
  30.             }  
  31.             Console.WriteLine("Enter the no 1 to " + arrayList.Count);  
  32.             int option =Convert.ToInt32(Console.ReadLine());  
  33.             if (option < arrayList.Count && option > 0)  
  34.             {  
  35.                 Console.WriteLine(option+ " position is  = " +arrayList[option - 1]);  
  36.             }  
  37.             else  
  38.             {  
  39.                 Console.WriteLine("Enter only 1 to " + arrayList.Count);  
  40.             }  
  41.             Console.ReadLine();  
  42.         }  
  43.     }  
  44. }
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now