Sometimes you will need to export some data from an ASP page and use another charset than the encoding you have specified in Web.config. If you have next line in web.config, all string response data from Response.Write method are converted to utf-8.
You can simply change response charset and content-type with next commands:
But if you try to write a string data using Response.Write method, the result will confuse client side - the response data will be encoded as utf-8, but response header will have charset=windows-1250. So you have to convert the unicode data to data with windows-1250 code page. I created short function to convert such data from Unicode (VB String) to another code page (for example windows-1250). I created a simple conversion function using System.Text.Encoding:
Then you can simply write:
for 'Convert data to another charset/codepage in vb net' articleConvert a binary data (BinaryRead) to a string by VBSThis article, demonstrates several versions of source VBS code you can use to work with binary data in ASP and convert the data to a String format.
Create and work with binary data in ASP/VBScriptLets you convert/create binary data in ASP to use the data for BinaryWrite/BinaryRead.
Copyright and use this code
The source code on this page and other samples at https://www.motobit.com/tips/ are a free code, you can use it as you want: copy it, modify it, use it in your products, ...
If you use this code, please:
1. Leave the author note in the source.
2. Link this sample from you page.
<A Href="https://www.motobit.com/tips/detpg_convert-charset-vbnet/" Title="Short sample to convert String Unicode data to another charset/codepage using System.Text.Encoding" >Convert data to another charset/codepage in vb net</A>
Do you like it? Rate me on LinkedIn
© 1996 - 2019 Antonin Foller, Motobit Software | About, Contacts