How do I replace whitespaces with underscore?

前端 未结 13 2159

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:39

    use string's replace method:

    "this should be connected".replace(" ", "_")

    "this_should_be_disconnected".replace("_", " ")

提交回复
热议问题