We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

Richard Comito
on
Medium Priority
250 Views
Last Modified: 2012-06-21
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
Comment
Watch Question

Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
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

Commented:

use print function instead of write function.

change

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

to

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
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.

Richard ComitoDirector of IT

Author

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)
Richard ComitoDirector of IT

Author

Commented:
Thanks appari,

That did the trick and the expiation helped also.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.