Replace all non Alpha Numeric characters, New Lines, and multiple White Space with one Space

后端 未结 8 1555
终归单人心
终归单人心 2021-01-29 20:24

I\'m looking for a neat RegEx solution to replace

  • All non Alpha-Numeric Characters
  • All NewLines
  • All multiple instances of white space
8条回答
  •  一生所求
    2021-01-29 20:47

    For anyone still strugging (like me...) after the above more expert replies, this works in Visual Studio 2019:

    outputString = Regex.Replace(inputString, @"\W", "_");
    

    Remember to add

    using System.Text.RegularExpressions;
    

提交回复
热议问题