• 有三个字符串,分别为 A 、B 、C,如何找出字符串C中以A开头、B结尾的子串?


    这里使用一个Python字符串对象的函数:

    |  find(...)
    |     S.find(sub [,start [,end]]) -> int
    |     
    |     Return the lowest index in S where substring sub is found,
    |     such that sub is contained within s[start:end]. Optional
    |     arguments start and end are interpreted as in slice notation.
    |     
    |     Return -1 on failure

     1 #_*_coding:utf-8_*_
     2 
     3 A = "world" ;
     4 B = "MaoGuy" ;
     5 
     6 C = "Hello,world.I am MaoGuy!" ;
     7 
     8 result = ""
     9 
    10 if C.find(A):
    11     startIndex = C.find(A)
    12     if C.find(B) > startIndex:
    13         endIndex = C.find(B) + len (B)
    14         result = C[startIndex:endIndex]
    15         
    16 print (result)
  • 相关阅读:
    The requested resource (/) is not available解决办法
    字符问题
    Unknown column in 'field list'
    table 和 div 简单布局
    css简介
    div 与 table 的优点
    瞎搞
    html
    小计--关联 复制表结构
    ddl dml dcl
  • 原文地址:https://www.cnblogs.com/maoguy/p/6560109.html
Copyright © 2020-2023  润新知