How do I replace whitespaces with underscore?

前端 未结 13 2183

I want to replace whitespace with underscore in a string to create nice URLs. So that for example:

\"This should be connected\" becomes \"This_should_be_conn         


        
13条回答
  •  余生分开走
    2020-11-29 16:30

    mystring.replace (" ", "_")
    

    if you assign this value to any variable, it will work

    s = mystring.replace (" ", "_")
    

    by default mystring wont have this

提交回复
热议问题