473,387 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can I remove text from a StringWriter ?

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
2 6902
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: hplloyd | last post by:
I am using some code off the web that requires a string builder in a script within a web page. In order to get the script to work I need to include the relevant library in the references section...
2
by: John Bowman | last post by:
Hello, I need to create some well formed XML text live in memory. What I really want is to use the XmlTextWriter object applied to some location in memory (Stream or something?), because it does...
8
by: Mikey | last post by:
I have an XML document as follows: <Menu> <Group> <Item Text="About Us" AccessRoles="All"> <Group> <Item Text="Option 1" AccessRoles="All" /> <Item Text="Option 2" AccessRoles="All" /> <Item...
3
by: Robert Linder | last post by:
I am trying to write 'StringWriter SW = new StringWriter();' to a FileStream. The code writes the text to file, but NotePad does not see the NewLines. Below is the code snippet taken from a...
2
by: Buddy Ackerman | last post by:
Apparently .NET strips these white space characters (MSXML doesn't) regardless of what the output method is set to. I'm using <xsl:text> </xsl:text> to output a tab character and...
2
by: Chad | last post by:
In our application, I would like to send out HTML mail. TO do so, I must do something like this: Mail.Body = <raw HTMLTEXT String> Hence, I would like to know how to get the HTML text for Web...
1
by: MAF | last post by:
Is there a simple way to get the text, xml, from an xmlwriter. I have a XML writer that writes to a file, and I want another function to return the text that the xml writer is produced. Any...
1
by: Andrus | last post by:
I need to remove all comments ( between <!-- and --tags) from XML string. I tried the following code but comments are still present. Or is it better to open xml string with a StreamReader, read...
2
by: Shimon Sim | last post by:
Hi I am writing some integration project. I need to create XML from object data but I don't need xml header and all the default namespaces. My current (testing) code is: Request request = new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.