Welcome to MSDN Blogs Sign in | Join | Help

Best Way to Make Your Own Encoding

Martin recently asked what the best way to roll his own encoding in .Net 2.0, in particular can you override Encoding/Encoder/Decoder, or should he write his own StreamWriter.

#1 is, of course, to use Unicode :), but apparently Martin doesn't have that option.

The answer is that you can write your own Encoding derived from the Encoding class and use it as any of the built-in Encodings.  They'll be a little slower in some cases due to some shortcuts we take internally, but otherwise you should be able to use them everywhere you use a normal Encoding/Encoder/Decoder object. 

There's an example of using the fallbacks at http://windowssdk.msdn.microsoft.com/en-us/library/tt6z1500.aspx, which isn't quite the same thing, but might help a little.

[updated 12 Oct 2006]
I've stuck an example of overriding encodings in this post: Example of overriding your own Encoding.

- Shawn

Published Friday, September 29, 2006 3:06 PM by shawnste
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Best Way to Make Your Own Encoding

Hi Shawn,

I'll be very happy to see some Own Encoding example here.

Regards,

Ivan.

Tuesday, October 03, 2006 10:14 AM by Ivan Petrov

# Example of overriding your own Encoding.

Previously I wrote about the Best Way to Make Your Own Encoding , but didn't include an example, so today

Thursday, October 12, 2006 7:09 PM by I'm not a Klingon

# Custom code pages? Redux

Warning: what is being described in this post is documented but is not supported. Please keep this mind

Saturday, May 19, 2007 12:40 PM by Sorting It All Out

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker