By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,505 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

Can I remove text from a StringWriter ?

P: n/a
Can I remove text from a StringWriter ?

I have a StringWriter object, the content of which looks like this:

"<div>Some other html which I wish to keep</div>"

Can I remove the unwanted <div>, </divtags? i.e. remove the last 4
characters and the first 3.

The context in which the object occurs, in asp.net code, is:

StringWriter sw = new StringWriter();
HtmlTextWriter htmlTw = new HtmlTextWriter(sw);
gvExcel.RenderControl(htmlTw);
Response.Write("<html>\r\n<head>\r\n");
Response.Write("<meta http-equiv=\"Content-Type\"
content=\"text/html; charset=UTF-8\" />\r\n");
Response.Write("</head>\r\n<body>\r\n");
Response.Write(sw.ToString());
Response.Write("\r\n</body>\r\n</html>");

This code is used to write a html file with a .xls extension which can
be loaded into excel.

I don't want the dummy <divto be there .

gvExcel is an asp.net GridView control.
May 12 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
here you go!
http://www.csharpfriends.com/Article...?articleID=132

Husam Al-A'araj

"Harry Haller" wrote:
Can I remove text from a StringWriter ?

I have a StringWriter object, the content of which looks like this:

"<div>Some other html which I wish to keep</div>"

Can I remove the unwanted <div>, </divtags? i.e. remove the last 4
characters and the first 3.

The context in which the object occurs, in asp.net code, is:

StringWriter sw = new StringWriter();
HtmlTextWriter htmlTw = new HtmlTextWriter(sw);
gvExcel.RenderControl(htmlTw);
Response.Write("<html>\r\n<head>\r\n");
Response.Write("<meta http-equiv=\"Content-Type\"
content=\"text/html; charset=UTF-8\" />\r\n");
Response.Write("</head>\r\n<body>\r\n");
Response.Write(sw.ToString());
Response.Write("\r\n</body>\r\n</html>");

This code is used to write a html file with a .xls extension which can
be loaded into excel.

I don't want the dummy <divto be there .

gvExcel is an asp.net GridView control.
May 12 '07 #2

P: n/a
Harry,

StringWriter derives from TextWriter, which (in a logical way) is meant
to provide a write once approach to writing text. A good example of
write-once semantics is a network stream, you can't change what you sent
once you sent it.

StringWriter is an implementation of TextWriter, but uses a
StringBuilder as the storage mechanism for the text being written. With
that in mind, once you are done using your StringWriter to write your text,
you can call the GetStringBuilder method and process the text in that before
you return it to the client.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Harry Haller" <Ha***@Steppenwolf.comwrote in message
news:cq********************************@4ax.com...
Can I remove text from a StringWriter ?

I have a StringWriter object, the content of which looks like this:

"<div>Some other html which I wish to keep</div>"

Can I remove the unwanted <div>, </divtags? i.e. remove the last 4
characters and the first 3.

The context in which the object occurs, in asp.net code, is:

StringWriter sw = new StringWriter();
HtmlTextWriter htmlTw = new HtmlTextWriter(sw);
gvExcel.RenderControl(htmlTw);
Response.Write("<html>\r\n<head>\r\n");
Response.Write("<meta http-equiv=\"Content-Type\"
content=\"text/html; charset=UTF-8\" />\r\n");
Response.Write("</head>\r\n<body>\r\n");
Response.Write(sw.ToString());
Response.Write("\r\n</body>\r\n</html>");

This code is used to write a html file with a .xls extension which can
be loaded into excel.

I don't want the dummy <divto be there .

gvExcel is an asp.net GridView control.

May 12 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.