大家好,又見面了,我是你們的朋友全棧君。
示例1:默認替換所有
s1 = '2019.10.30'
s2 = s1.replace('.', '-')
s2
'2019-10-30'
s1 # 不影響原字符串
'2019.10.30'
示例2:指定替換數量
s1 = '2019.10.30'
s2 = s1.replace('.', '-',1)
s2
'2019-10.30'
示例3:替換字符串
s1 = '2019.10.30'
s2 = s1.replace('19', '20')
s2
'2020.10.30'
發布者:全棧程序員棧長,轉載請注明出處:https://javaforall.cn/133975.html原文鏈接:https://javaforall.cn