python - Python,在解析字符串时,如果字符则换行
问题描述
如果我有一个如下所示的字符串(出于示例目的而简化)
myString =
"Hello world, the weather is nice today} How are you today?"
有没有一种方法可以解析字符串,并且
if "}" then \n
所以我的最终结果是,
"Hello world, the weather is nice today}
How are you today?"
解决方案
是的,使用replace()
方法:
myString = "Hello world, the weather is nice today} How are you today"
print(myString.replace('}', '}\n'))
输出:
Hello world, the weather is nice today}
How are you today
推荐阅读
- postgresql - 在 Postgres 中返回不受影响的行
- c# - 我不知道为什么经销商不打
- typescript - 当函数抛出错误时我们是否应该永远返回
- python - VPython:无论如何在动画开始之前显示画布?
- python - file.write 不会写入文件,但普通文本会 - 为什么会发生这种情况?
- firebase - 帐户不使用 GCP 计算时 GCP Compute Engine API 中的神秘指标
- python - 如何在没有单独的环境变量系统的情况下在本地从 Helm 获取值?
- python - 如何在 Python 中使生成的矩阵不重复?
- task - 创建虚拟 asyncio.Task
- directory - 使用 xargs 创建远程目录