可以使用Python代码来实现此操作:
string = "This is a string with spaces"
new_string = string.replace(" ", "_")
print(new_string)
This_is_a_string_with_spaces
这个代码将创建一个字符串并在其中搜索所有空格,然后使用str.replace()方法将其替换为下划线。
|
|
豁达的斑马 · Excel宏在左侧单元格中的数据复制粘贴到右侧。· 1 年前 · |
|
|
年轻有为的楼房 · 34.Python字符串替换方法transl ...· 2 年前 · |
|
|
打盹的水煮肉 · Python matplotlib ...· 2 年前 · |
|
|
坏坏的猴子 · jQuery.parseJSON() ...· 2 年前 · |
|
|
豪情万千的消防车 · 解决jupyter的能打开python文件无 ...· 2 年前 · |
| 字符串函数 python字符串连接 python字符串操作 下划线 |
| https://juejin.cn/s/%E6%80%8E%E4%B9%88%E5%B0%86%E7%A9%BA%E6%A0%BC%E6%9B%BF%E6%8D%A2%E4%B8%BA%E4%B8%8B%E5%88%92%E7%BA%BF |
|
|
悲伤的野马
2 年前 |
|
|
豁达的斑马 · Excel宏在左侧单元格中的数据复制粘贴到右侧。 1 年前 |