我的问题与字符串切片有关。我想提取以“ +”开头的字符串,直到字符串的结尾。我使用'indx'查找以'+'开头的每个子字符串的索引。除第一个子字符串外,其余所需的子字符串未正确提取。但是我的indx和字符串find()产生相同的结果,但子字符串输出错误
text = "Hello +Shahroz You gotta laugh +TriptiAgrawal at that.user You
gotta laugh at that +Thexyz1213 dudes been so broke"
indx=0
for word in text.split():
if word.startswith('+'):
print("Yes True")
print("indx1")
txt=text[indx:]
print("txt:"+txt)
indx += len(word)+1
输出应为:
+Shahroz You gotta laugh +TriptiAgrawal at that.user You
gotta laugh at that +Thexyz1213 dudes been so broke
+TriptiAgrawal at that.user You
gotta laugh at that +Thexyz1213 dudes been so broke
+Thexyz1213 dudes been so broke