Solved

NewBee string question

Posted on 2006-11-01
11
228 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
  • 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
Independent Software Vendors: 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

685 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