douzi8112 2015-07-01 10:48
浏览 51
已采纳

.Net - 用于清理垃圾字符的正则表达式

Can some one please help me to convert the following the PHP stuffs to .Net?

I don't enough idea in .Net and I need a regular expression to washout the junk chars from a decrypted string.

function clean($val) {
  return preg_replace('/[^A-Za-z0-9\-|||!@#$%&*. ]/', '', $val);
}
echo clean($val)
  • 写回答

1条回答 默认 最新

  • duandang2838 2015-07-01 11:01
    关注

    You can do it this way in C#:

    private string CleanStr(string val) 
    {
       return Regex.Replace(val, @"[^A-Za-z0-9\-|!@#$%&*. ]", string.Empty);
    }
    

    And then in the caller:

    Console.WriteLine(CleanStr("<<<Go>>>"));
    

    Result: Go

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?