Solved

NewBee string question

Posted on 2006-11-01
11
229 Views
Last Modified: 2011-09-20
Hi

Im trying to collect these html tags into a string.
but i keep getting this error msg " Too many characters in character litteral "


I put some quotes around the double quotes but that didnt work eigther.

string tmpstr = '"<html><head><title>Html Strings</title></head><body bgcolor="Gold" bgproperties="fixed"><table border="0" width="900" height="328" bgcolor="Gold"><tr><td width="100%" valign="top" height="324"></td></tr></table></body></html>"';

the only way i can get this to work ,is to replace all double qoutes with single quotes ...eg. <body bgcolor='Gold' bgproperties='fixed'>

Is there a easy workaround about this or how can/would i make some method to strip off all double quotes and replace them with single quotes.




vbturbo

0
Comment
Question by:vbturbo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 35

Assisted Solution

by:Raynard7
Raynard7 earned 125 total points
ID: 17848263
Hi - this is the problem - the double quotes - as these signify th ebeginning and end of the string

alternativley if you put \" instead of " then it should work ie

string tmpstr = "<html><head><title>Html Strings</title></head><body bgcolor=\"Gold\" bgproperties=\"fixed\"><table border=\"0\" width=\"900\" height=\"328\" bgcolor=\"Gold\"><tr><td width=\"100%\" valign=\"top\" height=\"324\"></td></tr></table></body></html>";
0
 
LVL 7

Accepted Solution

by:
mjmarlow earned 125 total points
ID: 17848273
C# string is enclosed in double quotes.
C# characters is enclosed in single quotes.
Your text above is enclosed in single quotes, thus the error.

You can create strings with embedded quotes using escape or @.  E.g.

Escape:
string s1 = "this is \"quoted\" string";

@
string s2 = @"this is ""quoted"" string";
0
 
LVL 18

Author Comment

by:vbturbo
ID: 17848332

Thanks for responce and solutions

but please carry over with me.
How do i get this to work ?

<body bgcolor='Gold' bgproperties='fixed' background='CID:|||c:\temp\logo.gif'>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:mjmarlow
ID: 17848439
What do you mean "work"?
0
 
LVL 18

Author Comment

by:vbturbo
ID: 17848455
Neighter of the examples below works

<body bgcolor='Gold' bgproperties='fixed' background='CID:|||@"c:\temp\logo.gif"'>

Or

<body bgcolor='Gold' bgproperties='fixed' background='CID:|||"\c:\temp\logo.gif\"'>
0
 
LVL 7

Expert Comment

by:mjmarlow
ID: 17849166
Still I am not sure what you mean by doesn't work.  If you want to assign a string this value:
"<body bgcolor='Gold' bgproperties='fixed' background='CID:|||c:\temp\logo.gif'>"
This is how i would do it:
string s = "<body bgcolor='Gold' bgproperties='fixed' background='CID:|||c:\temp\logo.gif'>";
0
 
LVL 7

Expert Comment

by:mjmarlow
ID: 17849180
If you are trying to programatically build up a string then use a StringBuilder.

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<html>");
sb.Append("<body bgcolor='Gold' bgproperties='fixed' background='CID:|||c:\temp\logo.gif'>");
sb.Append("</body></html>");
...
string html = sb.ToString();
0
 
LVL 18

Author Comment

by:vbturbo
ID: 17849464
thanks
0
 
LVL 7

Expert Comment

by:mjmarlow
ID: 17849765
Have you got it "working"?
0
 
LVL 18

Author Comment

by:vbturbo
ID: 17849951
Yes
It works as expected , although i adapted your approach


So thanks a lot

vbturbo
0
 
LVL 7

Expert Comment

by:mjmarlow
ID: 17851793
You're very welcome!  
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question