1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| Public Function Replace(ByVal MyString As String, ByVal ItemToFind As String, ByVal ItemToReplace As String) As String
Dim iPosit As Long
Dim strTemp As String
Dim strTemp1 As String
Dim strTemp2 As String
strTemp = MyString
iPosit = InStr(strTemp, ItemToFind)
While iPosit > 0
strTemp1 = Left(strTemp, iPosit - 1)
strTemp2 = Mid$(strTemp, iPosit + Len(ItemToFind))
strTemp = strTemp1 & ItemToReplace
iPosit = Len(strTemp)
strTemp = strTemp & strTemp2
iPosit = InStr(iPosit + 1, strTemp, ItemToFind)
Wend
Replace = strTemp
End Function
'====================================================
'SERAIT PEUT-ETRE MIEUX AINSI
'Function Replace(sInput As String, WhatToReplace As String, ReplaceWith As String) As String
'Dim Ret As Long
'Replace = sInput
'Ret = -Len(ReplaceWith) + 1
'Do
'Ret = InStr(Ret + Len(ReplaceWith), Replace, WhatToReplace, vbTextCompare)
'If Ret = 0 Then Exit Do
'Replace = Left$(Replace, Ret - 1) + ReplaceWith + Right$(Replace, Len(Replace) - Ret - Len(WhatToReplace) + 1)
'Loop
'End Function |
Partager