How to replace multiple consecutive question marks (?) with a single question mark in C#

1 Answer

0 votes
using System;
using System.Text.RegularExpressions;

class ReplaceQuestionMarks {
    static void Main() {
        string str = "Hello??? How are you?? What is your Wi-Fi password????";

        // Replace multiple '?' with a single '?'
        string result = Regex.Replace(str, @"\?+", "?");

        Console.WriteLine(result);
    }
}




/*
run:

Hello? How are you? What is your Wi-Fi password?

*/

 



answered Jul 24, 2025 by avibootz
...