hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Programming Tutorials : .NET StringWriter with Encoding
Reply

Programming Tutorials How-Tos related to programming, databases, and the like.
Forum Jump

.NET StringWriter with Encoding

Reply Post New Thread In Programming Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 07-05-2007, 04:37 PM
ChristsLittleFlock ChristsLittleFlock is online now
Web Hosting Master
 
Join Date: Jan 2005
Location: Johnstown, Pennsylvania
Posts: 1,269

.NET StringWriter with Encoding


The other day, I was trying to write a program to output an RSS feed. I used XmlWriter with StringWriter for the output. However, I noticed that the XML document consistently output an encoding of UTF16, despite setting XMLWriterSettings.Encoding to UTF-8.

In short, the solution was to create a StringWriter that supported changing the encoding. In this instance, the encoding can be passed to the constructor.

The class follows:

Code:
using System;
using System.IO;
using System.Text;

namespace Azavia.IO
{
    public class StringWriterWithEncoding : StringWriter
    {
        private Encoding _encoding;
        public StringWriterWithEncoding(Encoding encoding)
            : base()
        {
            _encoding = encoding;
        }
        public override Encoding Encoding
        {
            get
            {
                return _encoding;
            }
        }
    }
}

Reply With Quote


Sponsored Links
Reply

Related posts from TheWhir.com
Title Type Date Posted
Amazon Web Services Adds New EC2 Instances, Doubles IOPS for EBS Storage Volumes Web Hosting News 2012-11-02 16:46:48
Amazon's CloudFront CDN Grows with New Customers, Features, and Edge Locations Web Hosting News 2011-11-29 15:48:26


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?