How to replace multiple consecutive question marks (?) with a single question mark in VB.NET

1 Answer

0 votes
Imports System
Imports System.Text.RegularExpressions

Class ReplaceQuestionMarks
    Public Shared Sub Main()
        Dim str As String = "Hello??? How are you?? What is your Wi-Fi password????"
		
        Dim result As String = Regex.Replace(str, "\?+", "?")
		
        Console.WriteLine(result)
    End Sub
End Class



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

 



answered Jul 24, 2025 by avibootz
...