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


You need to login to view comments.