Access - funcion !!

 
Vista:

funcion !!

Publicado por david (9 intervenciones) el 05/05/2004 13:03:40
hola a todos, ¿existe alguna funcion que reemplace un caracter de una cadena por otro?
Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:funcion !!

Publicado por Ignacio (231 intervenciones) el 05/05/2004 16:26:48
Aquí la tienes:

Public Function Reemplazar(Texto As String, Cad1 As String, Cad2 As String) As String

' Devolver Texto habiendo reemplazado la Cad1 por la Cad2

Dim c As Integer, Pos1 As Integer, Pos2 As Integer, LargoCad1 As Integer
Dim Txt2 As String

If Texto = "" Or Cad1 = "" Or Len(Cad1) > Len(Texto) Then ' No procede
Reemplazar = Texto
Exit Function
End If

' Localizar Cad1
Pos1 = 0: Pos2 = 0: LargoCad1 = Len(Cad1)
For c = 1 To Len(Texto) - LargoCad1 + 1
If Mid(Texto, c, LargoCad1) = Cad1 Then
Pos1 = c
Pos2 = c + LargoCad1 - 1
Exit For
End If
Next

' Sustituir si procede
If Pos1 > 0 Then
Txt2 = Left$(Texto, Pos1 - 1) & Cad2 & Mid$(Texto, Pos2 + 1)
Reemplazar = Txt2
Else
Reemplazar = Texto
End If

End Function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar