How to remove the first occurrence of comma from a string in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string s = "c c++, java, python, c#";
        string comma = ",";
        
        int index = s.IndexOf(comma);
        
        s = (index < 0) ? s : s.Remove(index, comma.Length);

        Console.Write(s);
    }
}




/*
run:

c c++ java, python, c#

*/

 



answered Apr 18, 2022 by avibootz

Related questions

1 answer 129 views
1 answer 137 views
1 answer 126 views
1 answer 124 views
1 answer 126 views
1 answer 128 views
...