Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

NewBee string question

Posted on 2006-11-01
11
Medium Priority
?
234 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 500 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 500 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

916 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