python - 对于字符串中的某些字符,在紧接之前插入重复
问题描述
因此,我需要能够复制用户输入的字符串中的某个字符,例如:
Input: I\ love\ bac\kslashes\
Output: I\\ love\\ bac\\kslashes\\
据我所知,我复制反斜杠,转义字符无济于事......我该怎么做呢?
解决方案
你可以用str.replace()做到这一点:
userinput = input('Input your backslashed phrase')
replaceWith = '/'
newString = userinput.replace(replaceWith, replaceWith*2)
print(newString)
推荐阅读
- node.js - 将 GraphQL Schema 公开为 REST api 的方法有哪些?
- typescript - 无法在开玩笑的单元测试中模拟分页功能
- python - 有没有一种超级简单的方法来替换用户提示中的多个字符?(Python)
- sockets - 私人 P2P 聊天(NAT 穿越问题)
- python - 简单的代码,帮助,这里的菜鸟。在作业中,我不能只复制该功能。我怎样才能解决这个问题?
- python - FastApi:如何定义一个全局变量一次
- reactjs - 如何在 Reactjs 和 Tailwind CSS 中截断字符串
- kubernetes - 版本“v1”中没有匹配类型“Config”
- powerbi - 根据过滤器上选择的日期更改维度值
- angular - 构造函数中的函数调用