Writing a macro... replace function?
Writing a macro... replace function?
(OP)
I have been searching high and low for a replace function! Basically I just need to write something that looks at a string, removes all the double quotes and returns a clean string. We're doing process automation and our files come down in CSV format with quotes included.
I must not be looking hard enough because this is an elementary function. Anyone have an equivalent they've written? I'm about to toss this computer out the window, scaring the squirrels.
I must not be looking hard enough because this is an elementary function. Anyone have an equivalent they've written? I'm about to toss this computer out the window, scaring the squirrels.
RE: Writing a macro... replace function?
Hi,
You're going to have to write your own function. Loop thru the characters in the string, looking to the replace value.
Skip,
Don't let the Diatribe...![[tongue] tongue](https://www.tipmaster.com/images/tongue.gif)
Just traded in my old subtlety...
talk you to death!
for a NUANCE!
RE: Writing a macro... replace function?
myStr = Replace(MyStr, """", "")
RE: Writing a macro... replace function?
Have you checked in Extra Basic HELP?
Skip,
Don't let the Diatribe...![[tongue] tongue](https://www.tipmaster.com/images/tongue.gif)
Just traded in my old subtlety...
talk you to death!
for a NUANCE!
RE: Writing a macro... replace function?
I doctored up two solutions... one replaces a string with nothing, and one replaces a string with something:
Function RemoveChars(strText As String, strUnwanted As String) As String
Dim TempStr, CurChar As String
Dim x As Integer
For x = 1 To Len(strText)
CurChar = Mid(strText, x, 1)
If InStr(strUnwanted, CurChar) = 0 Then TempStr = TempStr & CurChar
Next x
RemoveChars = TempStr
End Function
Function ReplaceChars(strText As String, strUnwanted As String, strWanted as String) 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, 1)
If InStr(strUnwanted, tmpChar) Then
' Replace with the new character
Mid(strText, currLoc, 1) = strWanted
End If
Next
RemoveCharacters = strText
End Function