Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

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
0
Richard Comito
Asked:
Richard Comito
  • 2
  • 2
1 Solution
 
Fernando SotoRetiredCommented:
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

0
 
appariCommented:

use print function instead of write function.

change

Write(4, strTopEmail + strBottomEmail + strEmailBody2 + strEmailUnsubScribe + strEmailFooter)

to

Print(4, strTopEmail + strBottomEmail + strEmailBody2 + strEmailUnsubScribe + strEmailFooter)
0
 
appariCommented:
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.

0
 
Richard ComitoDirector of ITAuthor Commented:
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)
0
 
Richard ComitoDirector of ITAuthor Commented:
Thanks appari,

That did the trick and the expiation helped also.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now