在一个特定的子字符串之后获取字符串(Get a string after a specific substring)
如何在一个特定的子字符串之后得到一个字符串。
例如我想在my_string="hello python world , i'm a beginner " "world"中的"world"之后获取字符串my_string="hello python world , i'm a beginner "
how can i get a string after a specific substring .
For example I want to get the string after "world" in my_string="hello python world , i'm a beginner "
最满意答案
最简单的方法可能就是分开你的目标词
my_string="hello python world , i'm a beginner " print my_string.split("world",1)[1]split将单词(或字符)分割开,并可选择限制分割数。
在这个例子中,分为“世界”,并将其限制为只有一个拆分。
The easiest way is probably just to split on your target word
my_string="hello python world , i'm a beginner " print my_string.split("world",1)[1]split takes the word(or character) to split on and optionally a limit to the number of splits.
In this example split on "world" and limit it to only one split.
更多推荐
发布评论