我知道这是相当基本的,但是我想知道在两个参考点之间找到字符串的最佳方法。找到两点之间的字符串的最佳方法
例如:
找到2个逗号之间的字符串:
Hello, This is the string I want, blabla
我最初的想法是创建一个列表,并将它做这样的事情:
stringtext= []
commacount = 0
word=""
for i in "Hello, This is the string I want, blabla":
if i == "," and commacount != 1:
commacount = 1
elif i == "," and commacount == 1:
commacount = 0
if commacount == 1:
stringtext.append(i)
print stringtext
for e in stringtext:
word += str(e)
print word
然而我想知道是否有更简单的方法,或者可能只是简单的不同。谢谢!
三江源,我我知道我在做这件事:I – ReallyGoodPie 2013-05-14 13:19:05
@ReallyGoodPie它可能会通过一个不包含任何逗号的字符串和一个包含单个逗号的字符串来运行,并检查结果是否如您期望的那样。 – 2013-05-14 13:49:25
这就是我所期待的,并不完全是这样,但它对我所做的事很有用 – ReallyGoodPie 2013-05-14 13:57:43