fork(4) download
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Test {
  6. public static void Main() {
  7. // your code goes here
  8.  
  9. var file_name = GetValidFileName("filename with space %1.txt");
  10. Console.WriteLine(GetValidFileName(file_name));
  11.  
  12. }
  13. private static string GetValidFileName(string fileName) {
  14. // remove any invalid character from the filename.
  15. String ret = Regex.Replace(fileName.Trim(), "[^A-Za-z0-9_. ]+", "");
  16. return ret.Replace(" ", String.Empty);
  17. }
  18. }
Success #stdin #stdout 0.06s 34056KB
stdin
Standard input is empty
stdout
filenamewithspace1.txt