How to remove illegal characters from path and filenames?

前端 未结 29 2952
离开以前
离开以前 2020-11-22 17:18

I need a robust and simple way to remove illegal path and file characters from a simple string. I\'ve used the below code but it doesn\'t seem to do anything, what am I miss

29条回答
  •  伪装坚强ぢ
    2020-11-22 17:33

    I think it is much easier to validate using a regex and specifiing which characters are allowed, instead of trying to check for all bad characters. See these links: http://www.c-sharpcorner.com/UploadFile/prasad_1/RegExpPSD12062005021717AM/RegExpPSD.aspx http://www.windowsdevcenter.com/pub/a/oreilly/windows/news/csharp_0101.html

    Also, do a search for "regular expression editor"s, they help a lot. There are some around which even output the code in c# for you.

提交回复
热议问题