How can you strip non-ASCII characters from a string? (in C#)

前端 未结 11 1476
迷失自我
迷失自我 2020-11-22 17:24

How can you strip non-ASCII characters from a string? (in C#)

11条回答
  •  天涯浪人
    2020-11-22 17:43

    I use this regular expression to filter out bad characters in a filename.

    Regex.Replace(directory, "[^a-zA-Z0-9\\:_\- ]", "")
    

    That should be all the characters allowed for filenames.

提交回复
热议问题