1var string = "my name";
2string = string.replace(/ /g,"_"); //returns my_name
1// replaces space with '_'
2str = str.replace(/ /g, "_");
3// or
4str = str.split(' ').join('_');
1using System;
2class Demo {
3 static void Main() {
4 String str, str2;
5 str ="Hello World !";
6 Console.WriteLine("String: "+str);
7 str2 = str.Replace(" ", "-");
8 Console.WriteLine("String (After replacing): "+str2);
9 }
10}