在一个特定的子字符串之后获取字符串(Get a string after a specific substring)

编程入门 行业动态 更新时间:2024-10-26 11:14:05
在一个特定的子字符串之后获取字符串(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.

更多推荐

本文发布于:2023-08-02 16:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1378311.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   string   substring   specific

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!