Important alert: (current site time 7/15/2013 8:45:08 AM EDT)
 

winzip icon

ANSI Encoding

Email
Submitted on: 2/20/2005 7:12:02 PM
By: MstrControl  
Level: Intermediate
User Rating: By 2 Users
Compatibility: VB.NET
Views: 19019
(About the author)
 
     Many of us misses the old days when a character was represented by a single byte. These days we need to worry about codepages, character translations, and the works... Well Unicode chars came to our rescue and saved us from having to worry about all these stuff. But, sometimes we need to represent a string as an array of bytes. The .NET Framework provides several encoding mechanisms: ASCII, UTF7, UTF8, Unicode. Did you notice something missing? The good old ANSI. ANSI, to those who don't know it, is a super set of ASCII each char is represented by a single byte (range 0-255). ANSI Encoding is system dependent, but extremly efficient when handling with strings. The class I'm providing fill this gap. It provides a fast way to convert from a string to an array of ANSI bytes. Each char in the string (or char array) is converted to byte through Microsoft.VisualBasic.Asc function. So, I think it will be easy to understand. It's multi threaded in order to acheive performance. In my tests I was able to convert an string about 1,000,000 chars long in less than 3 senconds. *UPDATE* Fixed a little bug when handling strings and/ou byte arrays that was multiple of 256 in length. Added a Project Sample (along with a new status bar control)

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 7 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
4/8/2005 12:41:14 AM

hi, very nice buddy...
but I have a Q, in my C# desktop Application I'm trying to display arabic characters, but the result is a strange characters like this :
يا حبيبي كلما هب الهوى
so how can I convert them to real chars?
(If this comment was disrespectful, please report it.)

 
12/6/2005 5:50:11 PMThomas

Dude! I wonder how you only got an intermediate level rather than advanced.

I saw your code right above my binary typewriter and checked the picture and thought, "Wow! That's what I wan to do!"

I'll be filing through your code to see how in the world you made a rich text box do that.

5 outta 5
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.