如何用字符串中的_(下划线)替换空格?

时间:2014-04-25 12:10:09

标签: string replace str-replace

假设初始字符串是

String result= "Welcome To All" for that i need updated result as
String result="Welcome_To_All"  string value is dynamic,how can i do that,thank for help?

2 个答案:

答案 0 :(得分:0)

我相信这就是你正在寻找的东西

    string oldstr = "Hello World";
    string s = oldstr.Replace(" ", "_");
    (s == "Hello_World");

答案 1 :(得分:0)

我猜你正在使用javascript,你可以使用正则表达式。

result = result.replace(/ /g, "_");