Skip to content
Loading
  • 0
    m not getting you will u please explain with sample example
    0
  • 0
    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
  • 0
    I tried it in another way.Thanks for your Effort @Vasanti.
    I had some doubt .. 
    0
  • 0
    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"};   
    1. if (Array.StartsWith("Age 18"))  
    2. {  
    3. //Get those element starts with Age 18.  
    4. //Here there are three elements.  
    5. res [] arr={"Age18 mens for cricket","Age18 mens for football","Age18 mens for cricket captains"};  
    6. //I want to stroe to an array 
    7. }  
    How to do this...
    0
  • 0
    gives you the desired output but u would have used list rather than array 
     
     
    string get1 = "Age18";
    //string get2 = "Age20";
    int index1 = 0;
    //int index2 = 0;
    String[] array = { "Age18 is a batsman", "Age18 is a cricket", "Ram", "Raj", "Sonu", "Mano", "Age20", "Ana", "Einstein", "Somu", "Age18 is a football" };
    String[] result = {"entryelement"};
    foreach (string a in array)
    {
    if (a.StartsWith(get1))
    {
    index1 = Array.IndexOf(array, a);
    if (result[0] == "entryelement")
    result[0] = a;
    else
    Array.Resize(ref result, result.Length + 1);
    result[result.Length-1] = a;
    }
    }
    //foreach (string a in array)
    //{
    // if (a.StartsWith(get2))
    // {
    // index2 = Array.IndexOf(array, a);
    // }
    //}
    //var newArray = array.Skip(index1).Take(index2 - index1 + 1).ToArray();
    0