你可以使用正则表达式来找到句号,以下是一个示例代码:
import re
def find_dot(text):
pattern = r'\.'
match = re.search(pattern, text)
if match:
return match.start()
else:
return -1
# 示例用法
sentence = "标准的字符串rfind方法无法找到句号。"
dot_index = find_dot(sentence)
if dot_index != -1:
print("句号在索引", dot_index, "处")
else:
print("找不到句号")
这段代码使用了re.search()
函数来在文本中查找句号,如果找到了句号,则返回其索引位置,否则返回-1。
上一篇:标准的网页加载时间是多少?