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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete quptes

Status
Not open for further replies.

RLB2

Programmer
Nov 29, 2002
14
US
Hi,

I am using some code (below) to try to delete quotation marks in a file (txt). But i can't figure out how to delete the quotation mark (only one at a time - ")

Does anyone know how to do this. Your help is much appreciated!

Thanks!
Rob

Public Sub AASDBCleanTxtFile()

Dim dbs As Database
Dim rec As Recordset
Dim strSQL As String, strSQL2 As String, strSQL3 As String
Dim sql As String
Dim count As Integer
Dim NAME As String, PRICE As Double, Weight As Double, Cost As Double, TAX As Double
Dim SUBTOTAL As Double, TOTAL As Double
Dim fso As FileSystemObject
Dim tsMyFile As TextStream
Dim Trimmed As String
Dim strText As String
Dim ff As Integer
' Dim RegExp As Object

Set dbs = CurrentDb()
ff = FreeFile

PUBTxtFile = "C:\AAS\DB\Miva\ImportToWeb\MivaProductUpdateTXT1.txt"

' Set re = CreateObject("VBScript.RegExp")
' Set re = New RegExp
Set fso = New FileSystemObject
Set tsMyFile = fso_OpenTextFile(PUBTxtFile, ForReading)
Do Until tsMyFile.AtEndOfStream
strText = Replace(tsMyFile.ReadLine, Chr(10), vbCrLf)
strText = Replace(strText, "''", "")

If strText <> "" Then
Open "C:\AAS\DB\Miva\ImportToWeb\MivaProductUpdateTXT1_NEW.txt" For Output As #ff
Print #ff, strText
Close #ff
End If

DoEvents
Loop
Set re = Nothing
Set fso = Nothing

Set dbs = Nothing

End Sub
 
maybe...

strText = Replace(strText, chr$(34), "")
 
Or even:
Code:
strText = Replace(strText, """", "")

The outer double quotes delimit the string and inside a pair of double quotes get substituted by a one double quote.

I've also just noticed that your code is trying to replace a pair of apostrophes (not a "double quote" character) with nothing so maybe that's the real problem.


Bob Boffin
 
Hi All I managed to fix the problem! Thaks to everyones help! I made it a subroutine where I define public variables: (Makes it an all-purpose find and replace for txt files)
PUBTxtInputFile = "C:\TempInput.txt"
PUBTxtOutputFile = "C:\TempOutput.txt"
PUBTxtFind = ", "
PUBTxtReplaceWith = "::: "

Subroutine:
Set dbs = CurrentDb()
ff = FreeFile
strText = ""
strTextNew = ""

Set fso = New FileSystemObject
Set tsMyFile = fso_OpenTextFile(PUBTxtInputFile, ForReading)
Do Until tsMyFile.AtEndOfStream
'Replaces linefeed with corect linefeed character
' strTextNew = Replace(tsMyFile.ReadLine, Chr(10), vbCrLf)
strTextNew = Replace(tsMyFile.ReadLine, PUBTxtFind, PUBTxtReplaceWith)
If strText <> "" Then
strText = strText & vbCrLf & strTextNew
Else
strText = strTextNew
End If
DoEvents
Loop
If strText <> "" Then
Open PUBTxtOutputFile For Output As #ff
Print #ff, strText
Close #ff
End If

Set re = Nothing
Set fso = Nothing

Set dbs = Nothing

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top