wessir
asked on
Replace double quotes in a text file?
I have a need to read text files into an ADO recordset. Some of my files have double quotes in them (out of my control to prevent that) and when reading those records into my recordset the double quote causes a misread of the record (record ends at first double quote " in source file line).
Is there a way to use the streamreader and streamwriter to create a new file from the input file, read it one character at a time, and replace any undesired characters - in this case the double quotes would need to be replaced by single quotes.
Could that also be used to replace by hex code of the character?
Is there a way to use the streamreader and streamwriter to create a new file from the input file, read it one character at a time, and replace any undesired characters - in this case the double quotes would need to be replaced by single quotes.
Could that also be used to replace by hex code of the character?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Grading comment:
Oh! How did I miss that. Thanks! Here's my code using your suggestion.
Oh! How did I miss that. Thanks! Here's my code using your suggestion.
Dim sr As New StreamReader(strInputFile)
Dim sw As New StreamWriter(strOutputFile)
Dim str As String
Do While sr.Peek() >= 0
str = sr.ReadLine.Replace(Chr(34), Chr(39))
sw.WriteLine(str)
Loop
sr.Close()
sw.Close()
sr.Dispose()
sw.Dispose()
ASKER
Dim sr As New StreamReader(strInputFile)
Dim sw As New StreamWriter(strOutputFile
Dim str As String
Do While sr.Peek() >= 0
str = sr.ReadLine.Replace(Chr(34
sw.WriteLine(str)
Loop
sr.Close()
sw.Close()
sr.Dispose()
sw.Dispose()