Skip to content
Loading
Get the array element in between a string in c#
  • I tried it in another way.Thanks for your Effort @Vasanti.
    I had some doubt .. 
    0
  • string get1 = "Age18";
    string get2 = "Age20";
    int index1=0, index2=0;
    String[] array = { "Age18 is a batsman", "Ram", "Raj", "Sonu", "Mano", "Age20", "Ana", "Einstein", "Somu" };
    foreach (string a in array)
    {
    if (get1.Contains(a))
    {
    index1 = Array.IndexOf(array, a);
    }
    }
    foreach (string a in array)
    {
    if (get2.Contains(a))
    {
    index2 = Array.IndexOf(array, a);
    }
    }
    var newArray = array.Skip(index1).Take(index2 - index1 + 1).ToArray();
    +1
    1. String [] Array= {"Age18 mens for cricket" ,"Ram","Raj" ,"Sonu","Mano",      
    2.                   "Age18 mens for football","Ana","Einstein","Somu",      
    3.                   "Age18 mens for cricket captains","Asd","Ashik"};    

    4. This is my array Here I want split The Contents   res[]arr= {" Age18 mens for                                                        cricket","Ram","Raj" ,"Sonu","Mano" };

    5. Actually Your Solution is right if the Array element is Age18. But here the array element starts with Age18....something........ 
    0
  • m not getting you will u please explain with sample example
    0
    1. String [] Array= {"Age18 are classified ........" ,"Ram","Raj" ,"Sonu","Mano","Age20","Ana","Einstein","Somu"};   
    Actually The array element is not Age 18.The line is start with Age 18 .......
    Now how to filter the element....@ 

    Vasanti

    0
  • String[] array = { "Age18", "Ram", "Raj", "Sonu", "Mano", "Age20", "Ana", "Einstein", "Somu" };
    int index1 = Array.IndexOf(array, "Age18");
    int index2 = Array.IndexOf(array, "Age20");
    var newArray = array.Skip(index1).Take(index2 - index1 + 1).ToArray();
    +1