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. namespace SplitStringWithoutUsingSplitMethod
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string str = "This,is,C#,Corner,Website";
  14. ArrayList arrayList = new ArrayList();
  15. string Temp = "";
  16. for (int i = 0; i < str.Length; i++)
  17. {
  18. if (str[i] != ',')
  19. {
  20. Temp = Temp + str[i];
  21. continue;
  22. }
  23. arrayList.Add(Temp);
  24. Temp = "";
  25. }
  26. Console.WriteLine("Enter the no 1 to " + arrayList.Count);
  27. int option =Convert.ToInt32(Console.ReadLine());
  28. if (option < arrayList.Count && option > 0)
  29. {
  30. Console.WriteLine(option+ " position is = " +arrayList[option - 1]);
  31. }
  32. else
  33. {
  34. Console.WriteLine("Enter only 1 to " + arrayList.Count);
  35. }
  36. Console.ReadLine();
  37. }
  38. }
  39. }