python 也沒有 replaceAll,需要自己寫一個

# python 的 replaceAll

def replaceAll( input, toReplace, replaceWith ): #
    while ( input.find( toReplace ) > -1 ):
        input = input.replace( toReplace, replaceWith )
     
    return input
#  

 

調用它:

file = 'q123q456q'
toReplace = 'q'
replaceWith = '-'

file = replaceAll( file, toReplace, replaceWith )
    
print( file )        # 打印結果 -123-456-

發佈了423 篇原創文章 · 獲贊 58 · 訪問量 42萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章