python - Python从字符串中的开头到第一个特定字符删除?
问题描述
假设我有以下字符串:
this is ;a cool test
如何删除从启动到第一次;
发生的所有内容?预期的输出将是a cool test
。
我只知道如何使用方括号表示法删除固定数量的字符,这在这里没有帮助,因为 的位置;
不固定。
解决方案
使用str.find
和切片。
前任:
s = "this is ;a cool test; Hello World."
print(s[s.find(";")+1:])
# --> a cool test; Hello World.
或使用str.split
前任:
s = "this is ;a cool test; Hello World."
print(s.split(";", 1)[-1])
# --> a cool test; Hello World.
推荐阅读
- mysql - Laravel Eloquent,如何在 3 张桌子上访问 eloquent?
- vbscript - 简单循环和 cpu 过度使用的 VBS 和 WSH 错误
- c# - 以编程方式 ComboBox VirtualizingStackPanel WPF
- java - 如何解决多线程静态变量递增?
- web-config - 我想将我的 .htaccess 更改为 web.config 下面是我的文件
- typescript - webpack-streams 打破了@types/webpack
- arrays - 在 BASH 中为单词数组加边框
- reactjs - 如何在不需要时阻止要调用的功能组件?依赖在哪里?
- php - 带有网格布局的 CSS 和 PHP - 来自 mysql 的动态数据 - 为每组行创建标题
- django - 在我的 Django 数据库中保存外部 kraken API json?