How to print all the substring that start with a specific character in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        public int Length { get; private set; }

        static void Main(string[] args)
        {
            const string s = "java c# c++ ada";

            int i = 0;
            while ((i = s.IndexOf('a', i)) != -1)
            {
                Console.WriteLine(s.Substring(i));

                i++;
            }
        }
    }
}


/*
run:
     
ava c# c++ ada
a c# c++ ada
ada
a

*/

 



answered Dec 25, 2016 by avibootz
...