Replace invalid to valid file name


/ Published in: C#
Save to your folder(s)

Replace invalid to valid file name by using RegEx


Copy this code and paste it in your HTML
  1. static string removeBadChar(string filename)
  2. {
  3. // Replace invalid characters with "_" char.
  4. return Regex.Replace(filename, @"[^\w\.-]", "_");
  5.  
  6. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.