python 字符串只替换一次函数,支持汉字

def oneReplace(mystr,Findstr,Repstr):
    #Findstr=Findstr.decode('utf-8').encode('gb18030') 
    idx=mystr.find(Findstr)
    strlen=len(Findstr.decode('utf-8'))
    arcpy.AddMessage("idx:"+str(idx)+""+Findstr+"长度:"+str(strlen))
    if idx<0:
        return mystr
    return mystr[0:idx]+Repstr+mystr[idx+strlen:]

猜你喜欢

转载自www.cnblogs.com/gisoracle/p/10946786.html