How to get substring between two strings include the strings in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string s = "c# c++ c vb.net java python";  
        
        string s1 = "c++";
        string s2 = "java";      
        
        int s1Index = s.IndexOf(s1);    
        int s2Index = s.IndexOf(s2);  

        string subs = s.Substring(s1Index, s2Index - s1Index + s2.Length);      
        Console.WriteLine(subs);
    }
}




/*
run:

c++ c vb.net java

*/

 



answered Feb 24, 2021 by avibootz

Related questions

2 answers 191 views
1 answer 95 views
1 answer 179 views
1 answer 85 views
...