Solved

NewBee string question

Posted on 2006-11-01
11
226 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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