Loading ...

Replace spaces with underscores in csharp | CodeAsp.Net

Replace spaces with underscores in csharp

 /5
0 (0votes)

In this blog I will explain you how to replace spaces with underscores in a string. To explain it I have used regular expression. Below is the code snippet:

 

static void Main(string[] args)

{

string testString = "This is test";

Console.WriteLine(Replace(testString));

Console.ReadLine();

}

static string Replace(string str)

{

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

}

 

 

 

Happy Reading.!

 

Comments (no comments yet)

Top Posts