Created
October 20, 2011 19:30
-
-
Save sorted-bits/1302069 to your computer and use it in GitHub Desktop.
String to valid filename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static public string ToValidFileName(this string name) | |
{ | |
string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars())); | |
string invalidReStr = string.Format(@"[{0}]+", invalidChars); | |
return Regex.Replace(name, invalidReStr, "_"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment