python - 如果出现子字符串,则拆分字符串

标签 python string split

我怎么能说如果一个字符串命中 https(没有空格)将它分成两个词? 例如在 Join us!https://t.co/Fe0oTahdom 中想要让它像 Join us!https://t.co/Fe0oTahdom

最佳答案

最简单的方法,如果你只打算在 https 关键字上拆分

myString = 'Join us!https://t.co/Fe0oTahdom'

(head, sep, tail) = myString.partition('https')

print head  #Prints Join us!
print sep + tail #Prints the rest

关于python - 如果出现子字符串,则拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33425511/

相关文章:

python - 如何根据另一列添加到 Pandas 列

python - 在 detectorron2 中,如何在对象检测中仅绘制没有标签(类名)的图像上的边界?

java - 字符串类的 subString() 函数是如何工作的

python - 在空格后拆分字符串

r - 根据列值有条件地将 data.table 划分为子表

python - 如何保护客户端与 HBase Thrift 服务器的连接?

Python - 从文件中读取第二列

c# - pdf C# 中的下标文本

javascript - Android 将 JavaScript 代码绑定(bind)到 Android 代码不起作用?

Java:计算字符串中序列的频率