How to trim string after character in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string str = "c# c c++ java python php";
        char ch = 'p';
        int trimIndex = str.IndexOf(ch);
        
        if (trimIndex >= 0) {
            str= str.Substring(0, trimIndex + 1);
            Console.WriteLine(str); 
        }
    }
}




/*
run:

c# c c++ java p

*/

 



answered Aug 15, 2023 by avibootz

Related questions

1 answer 203 views
1 answer 175 views
1 answer 285 views
1 answer 213 views
1 answer 186 views
186 views asked Jul 30, 2023 by avibootz
1 answer 186 views
1 answer 187 views
...