Checking for specific character in string and replacing it

mcdhappy80

Registered User.
Local time
Today, 09:12
Joined
Jun 22, 2009
Messages
347
I need a code template for a function that will check for a specific character in a string and then replace it with the one i provide?

Thank You.
 
I need a code template for a function that will check for a specific character in a string and then replace it with the one i provide?

Thank You.

You should not need to make a new Function when the built in Replace() Function will probably get you where you want. Check it out and get back if it is not what you want.
 
[SOLVED] Checking for specific character in string and replacing it

You should not need to make a new Function when the built in Replace() Function will probably get you where you want. Check it out and get back if it is not what you want.

Thank You for Your answer.
Ha ha, while I was waiting for the answer I built the function that aready exists :)

I originally intended to check if the date holds "/" character and replace it.
Here's the function:
Code:
Dim datum As Date
Dim i As Integer
Dim strIsp As String
Dim strCur As String
Dim strFin As String

datum = FormatDateTime(Now(), vbShortDate)
    
For i = 1 To Len(datum)
    strCur = Mid(datum, i, 1)
    
    If strCur = "/" Or strCur = "." Then
        strCur = "_"
    End If
    
    strIsp = strCur
    
    strFin = strFin + strIsp
    'MsgBox strFin
    strCur = ""
Next i
    
MsgBox strFin
Thank You
 
Re: [SOLVED] Checking for specific character in string and replacing it

Thank You for Your answer.
Ha ha, while I was waiting for the answer I built the function that aready exists :)
Yep, that happens sometimes :D

It is fun when you spend time creating something just to find out that a single line will do the work you just created using many lines of code. I've been there. :)
 

Users who are viewing this thread

Back
Top Bottom