Find and Replace 2 characters at once!! HELP
Hi All... my brain is going to pop. I am writing a small application that allows you to cut and paste text from anything into a text box and then have it re-formatted taking out certain CRs and replacing them with others.
If it were a simple find and replace that would be no problem, but, this is what I want to do:
I want to find all instances of chr(34) and chr(46) (. & ") at the same time and replace them with . " # at the same time - make sense? (the reason I want to add the # is because I am going to newline that afterwards)
How can I find two characters together and replace with 3?
If I replace them seperately they will replace all instances of '.' (for instance) throughout the whole string. I only want to replace when the two (.") are next to each other.
here is some code I have been playing with - but it doesn't work as such! I must be close - the pain in my head tells me so ;)
Any tips much appreciated... Sco
---------------------------------------
firstfind = Chr(46) + Chr(13)
RemoveCharacters(TextBox1.Text, firstfind) >>> calls
Public Function RemoveCharacters(ByRef strText As String, _
ByRef strUnwanted As Char) As String
Dim currLoc As Integer
Dim StringLength As Integer
Dim tmpChar As String
StringLength = Len(strText)
For currLoc = 1 To StringLength
tmpChar = Mid(strText, currLoc, 2)
If InStr(strUnwanted, tmpChar) Then
Mid(strText, currLoc, 3) = Chr(46) + Chr(34) + Chr(35)
End If
Next
RemoveCharacters = strText
End Function
|