- '----------------------------------------------------------------------------------------
- ' Nom : RSTR_Remplace
- '
- ' But : Permet de remplacer une partie d'une chaine par une autre
- '
- ' Paramètres : pstrChaineComplete : Chaine complete avant traitement
- ' pstrChaineCherchee : Chaine que l'on veut remplacer
- ' pstrChaineRemplacement : Chaine de remplacement de la chaine cherchee
- ' Fonctions appelées : -
- '
- ' Valeur de retour : Chaine de caractères si OK , "ERREUR" si... erreur :)
- ' Auteur : Jean-Francis Date : 14/11/2002
- '----------------------------------------------------------------------------------------
- Public Function RSTR_Remplace(ByVal pstrChaineComplete As String, ByVal pstrChaineCherchee As String, ByVal pstrChaineRemplacement As String) As String
-
- On Error GoTo err:
-
- Dim lngPosition As Long
- Dim lngLongueur As Long
-
- If LenB(pstrChaineRemplacement) = 0 Then
- Exit Function
- End If
-
- lngLongueur = Len(pstrChaineCherchee)
-
- lngPosition = InStr(pstrChaineComplete, pstrChaineCherchee)
-
- Do While lngPosition <> 0
- If lngPosition = 1 Then
- pstrChaineComplete = pstrChaineRemplacement & Mid$(pstrChaineComplete, lngLongueur + 1)
- Else
- pstrChaineComplete = Left$(pstrChaineComplete, lngPosition - 1) & pstrChaineRemplacement & Mid$(pstrChaineComplete, lngPosition + lngLongueur)
- End If
- lngPosition = InStr(pstrChaineComplete, pstrChaineCherchee)
- Loop
-
- RSTR_Remplace = pstrChaineComplete
-
- Exit Function
-
- err:
- RSTR_Remplace = "ERREUR"
-
- End Function
'----------------------------------------------------------------------------------------
' Nom : RSTR_Remplace
'
' But : Permet de remplacer une partie d'une chaine par une autre
'
' Paramètres : pstrChaineComplete : Chaine complete avant traitement
' pstrChaineCherchee : Chaine que l'on veut remplacer
' pstrChaineRemplacement : Chaine de remplacement de la chaine cherchee
' Fonctions appelées : -
'
' Valeur de retour : Chaine de caractères si OK , "ERREUR" si... erreur :)
' Auteur : Jean-Francis Date : 14/11/2002
'----------------------------------------------------------------------------------------
Public Function RSTR_Remplace(ByVal pstrChaineComplete As String, ByVal pstrChaineCherchee As String, ByVal pstrChaineRemplacement As String) As String
On Error GoTo err:
Dim lngPosition As Long
Dim lngLongueur As Long
If LenB(pstrChaineRemplacement) = 0 Then
Exit Function
End If
lngLongueur = Len(pstrChaineCherchee)
lngPosition = InStr(pstrChaineComplete, pstrChaineCherchee)
Do While lngPosition <> 0
If lngPosition = 1 Then
pstrChaineComplete = pstrChaineRemplacement & Mid$(pstrChaineComplete, lngLongueur + 1)
Else
pstrChaineComplete = Left$(pstrChaineComplete, lngPosition - 1) & pstrChaineRemplacement & Mid$(pstrChaineComplete, lngPosition + lngLongueur)
End If
lngPosition = InStr(pstrChaineComplete, pstrChaineCherchee)
Loop
RSTR_Remplace = pstrChaineComplete
Exit Function
err:
RSTR_Remplace = "ERREUR"
End Function