Posted By

tranvinhnt on 02/18/08


Tagged

regex valid replace filename


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


Replace invalid to valid file name


 / Published in: C#
 

Replace invalid to valid file name by using RegEx

  1. static string removeBadChar(string filename)
  2. {
  3. // Replace invalid characters with "_" char.
  4. return Regex.Replace(filename, @"[^\w\.-]", "_");
  5.  
  6. }

Report this snippet  

You need to login to post a comment.