Loading ...

How to remove spaces in filenames | CodeAsp.Net

How to remove spaces in filenames

 /5
0 (0votes)

In this blog I will explain you how to remove blank spaces from filenames. There are scenarios where we have to deal with files but we want to remove blank spaces from the filenames. Below is the code snippet I have used regular expression to explain it.

 

static void Main(string[] args)

{

string testString = "This is test file name";

Console.WriteLine(Replace(testString));

Console.ReadLine();

}

static string Replace(string str)

{

return System.Text.RegularExpressions.Regex.Replace(str, @"\s+", "");

}

It will give the output: Thisistestfilename

 

Happy Reading .!

 

Comments (1)

   
rtpHarry
This would also work:

string testString = "This is test file name";
testString.Replace(@"\s+", string.Empty);

or even just

string testString = "This is test file name";
testString.Replace(" ", string.Empty);
8/22/2009
 · 
by

Top Posts