# 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-
本文介绍了一个简单的Python函数,用于在字符串中替换所有指定字符。通过一个示例演示了如何使用此函数将字符串中的特定字符替换为另一种字符。
536

被折叠的 条评论
为什么被折叠?



