Solved

NewBee string question

Posted on 2006-11-01
11
224 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now