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:]
相關文章
相關標籤/搜索