Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing a macro... replace function?

Status
Not open for further replies.

diabolik69

Programmer
Feb 16, 2009
3
US
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.
 



Hi,

You're going to have to write your own function. Loop thru the characters in the string, looking to the replace value.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Does Extra! Basic have a Replace function similar to MS VB?

myStr = Replace(MyStr, """", "")

 



Have you checked in Extra Basic HELP?

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I checked and saw nothing in there.

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top