How to remove the last occurrence of a character from a string in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string str = "csharp javascript c++";
        
        int lastIndexOf_p = str.LastIndexOf('p');
        
        str = str.Substring(0, lastIndexOf_p) + str.Substring(lastIndexOf_p + 1);
        
        Console.WriteLine(str);
    }
}




/*
run:

csharp javascrit c++

*/

 



answered Jun 13, 2022 by avibootz
...