Link to home
Start Free TrialLog in
Avatar of Richard Comito
Richard ComitoFlag for United States of America

asked on

How can I replace a double quote at the begging of the string and at the end of the string?

I have the following code that I am using to write a string  to an HTML File.  However, when the string is written to the file I get a double quote at the begging of the string and one at the end of the string.  I would like to just replace those two quotes without replacing all the quotes in the entire string.  How would I go about doing this?

This is the line that I am having trouble with.  " Write(4, Replace(strTopEmail.ToString, chr(34), "", 1, 1, CompareMethod.Text) + strBottomEmail + strEmailBody2 + strEmailUnsubScribe + strEmailFooter)"

Thanks  

                          If intCount = 1 Then
                                If File.Exists("\\192.168.0.30\c$\website\LASA2\weeklyemail\default.html") Then
                                    File.Delete("\\192.168.0.30\c$\website\LASA2\weeklyemail\default.html")
                                    FileOpen(4, "\\192.168.0.30\c$\website\LASA2\weeklyemail\default.html", OpenMode.Append, OpenAccess.Write)
                                    Write(4, Replace(strTopEmail.ToString, chr(34)", "", 1, 1, CompareMethod.Text) + strBottomEmail + strEmailBody2 + strEmailUnsubScribe + strEmailFooter)
                                    FileClose(4)
                                Else
                                    FileOpen(4, "\\192.168.0.30\c$\website\LASA2\weeklyemail\default.html", OpenMode.Append, OpenAccess.Write)
                                    Write(4, strTopEmail + strBottomEmail + strEmailBody2 + strEmailUnsubScribe + strEmailFooter)
                                    FileClose(4)
                                End If
                            End If
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi GabicusC;

if the following line of code outputs one line to the HTML file, meanning no CrLf in the line:

Replace(strTopEmail.ToString, "„", "", 1, 1, CompareMethod.Text) + strBottomEmail + strEmailBody2 + strEmailUnsubScribe + strEmailFooter

Then this line of code will do what you want.

System.Text.RegularExpressions.Replace(Replace(strTopEmail.ToString, "„", "", 1, 1, CompareMethod.Text) + strBottomEmail + strEmailBody2 + strEmailUnsubScribe + strEmailFooter, "^(")|(")$", "")

I hope that this is of some help.

Fernando

ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
from MSDN

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmWrite.asp?frame=true

Unlike the Print function, the Write function inserts commas between items and quotation marks around strings as they are written to the file. You don't have to put explicit delimiters in the list.

Avatar of Richard Comito

ASKER

Thanks fernando for your reply.

However I am getting the following error when I try and use your suggestion.

("Replace" is not a member of RegularExpressions)
Thanks appari,

That did the trick and the expiation helped also.