python中获得一个字符串最后出现位置


def lastpos(findstr,mystr):
        #gp.AddMessage("查询=======:"+findstr+","+mystr)
        num=len(mystr)
        #gp.AddMessage("长度:"+str(num))
        findnum=len(findstr)
        #gp.AddMessage("长度,findnum="+str(findnum))
        i=num-findnum
        #gp.AddMessage("查询:i="+str(i)+",num="+str(num))
        while i>0:               
                p=mystr.find(findstr,i,num)
                #gp.AddMessage("查询:p="+str(p))
                if p>0:
                        return p
                i=i-1
               
      


def gettfh(filename): #获得图幅号
        filepath=os.path.dirname(filename)
        #gp.AddMessage("查询:p="+filepath)
        p=lastpos("\\",filepath)
        num=len(filepath);
        return filepath[p+1:num]

原文地址:https://www.cnblogs.com/gisoracle/p/1876295.html