We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

tranvinhnt on 02/18/08


Tagged

regex valid replace filename


Versions (?)


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.