Skip to content

Instantly share code, notes, and snippets.

@sorted-bits
Created October 20, 2011 19:30
Show Gist options
  • Save sorted-bits/1302069 to your computer and use it in GitHub Desktop.
Save sorted-bits/1302069 to your computer and use it in GitHub Desktop.
String to valid filename
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