How to remove the last comma from the end of string in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string s = "c,c++,c#,python,java,";
        
        if (s.EndsWith(',')) {
            s = s.TrimEnd(',');
        }

        Console.Write(s);
    }
}



/*
run:

c,c++,c#,python,java

*/

 



answered Apr 12, 2022 by avibootz

Related questions

1 answer 129 views
1 answer 182 views
1 answer 155 views
1 answer 142 views
1 answer 150 views
2 answers 186 views
2 answers 184 views
...