473,725 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unicode to Ansi Conversion

I have written an application which uses a streamwriter to create which is
exported to a third party system. The third party system does not appear to
process the files in its original format. I have identified this as resulting
from the streamwriter outputing in Unicode.

If I open the text file using notepad and save it with the default 'ansi'
type the import works fine. How can I convert the initial file to ansi.

Thanks in advance for any replies!
Jan 23 '08 #1
4 6320
"Gino" <ia*********@tw oway-logistics.comwr ote in message
news:F3******** *************** ***********@mic rosoft.com...
>I have written an application which uses a streamwriter to create which is
exported to a third party system. The third party system does not appear
to
process the files in its original format. I have identified this as
resulting
from the streamwriter outputing in Unicode.

If I open the text file using notepad and save it with the default 'ansi'
type the import works fine. How can I convert the initial file to ansi.
StreamWriter Constructor (String, Boolean, Encoding)

Dim MyEncoding As Encoding = Encoding.ASCII
Dim f As String = "C:\Temp\SomeFi le.txt"
Dim sw As New StreamWriter(f, False, MyEncoding)

sw.Write(LoadsO fCrap)
sw.Close()
Thanks in advance for any replies!
Rude pig.


Jan 23 '08 #2
Gino,

What do you mean with Ansi, all the replies you got where about the ancient
7 bit ASCII code. However that is not Ansi.

Your Unicode is Ansi

http://en.wikipedia.org/wiki/Code_page

You can use the code provided until now in this messagethread, but take than
the proper encoding.

http://msdn2.microsoft.com/en-us/lib...ng(VS.71).aspx

Cor

Jan 23 '08 #3
Gino,

While answering the question from Lorenzo, I remebered that I once had
answered this questiong with this one.

Be aware that this is the American/Dutch code page (it is the only one with
the guilder character in it).

\\\
Dim Str As New StreamReader(Fi lePath)
Dim arrInput As Byte() = _
System.Text.Enc oding.GetEncodi ng(437).GetByte s(Str.ReadToEnd )
Str.Close()
///

Cor

Jan 23 '08 #4
"Guru" <ru*****@interf erence.nitschri eb:
>>I have written an application which uses a streamwriter to create which is
exported to a third party system. The third party system does not appear
to
process the files in its original format. I have identified this as
resulting
from the streamwriter outputing in Unicode.

If I open the text file using notepad and save it with the default 'ansi'
type the import works fine. How can I convert the initial file to ansi.

StreamWriter Constructor (String, Boolean, Encoding)

Dim MyEncoding As Encoding = Encoding.ASCII
ASCII != ANSI.

Use 'Encoding.Defau lt' to use the system's default Windows ANSI codepage, or
use 'Encoding.GetEn coding(<codepag e number>)' to get a specific Windows ANSI
codepage.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 23 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2636
by: Thomas Heller | last post by:
I was trying to track down a bug in py2exe where the executable did not work when it is in a directory containing japanese characters. Then, I discovered that part of the problem is in the zipimporter that py2exe uses, and finally I found that it didn't even work in Python itself. If the entry in sys.path contains normal western characters, umlauts for example, it works fine. But when I copied some japanese characters from a random...
1
4455
by: Paul | last post by:
Hi, I am extending an existing MFC app to use Unicode (for a Japanese version of the interface elements). The app's purpose is to control a peripheral device through the serial port, and the device only understands ansi strings (in fact, I synthesize a character stream and send it as though it was typed into a terminal). The problem seems to be that the VC++ 6 linker insists that if I use the #define UNICODE and _UNICODE preprocessor...
18
34140
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found Encoding.Convert, but that needs byte arrays. Thanks, /Ger
40
3237
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages, including asian languages (chinese, japanese, korean, etc). First of all, strings will be passed to my class methods, some of which based on the language (and on the encoding) might contain characters that require more that a single byte.
4
430
by: ankan.banerjee | last post by:
Hi, I am currently trying to get an application to support Turkish language... The exact scenario is that we are trying to execute a BULK INSERT query in our MS SQL database based on a data file we have. The datafile itself is stored in ANSI format but has Turkish characters like 'S' which is represented in the hex code 0xDE. If I import this file into the DB I get the character 'Þ' instead which is U+00DE instead of getting U+015E.
9
13648
by: emagzz | last post by:
Hi all, I need to convert many text file from ANSI to UNICODE. Some body knows if there is a free utility that can do this from the command line so as I can use it inside a batch file. Thank you Emanuele
6
18050
by: msdnuniv | last post by:
Hello everybody, since days i try to convert Unicode-Strings in VB.NET to ANSI which should be processable in VB6 and converted to unicode again. It should be possible with any codepage, e.g. somebody on a greek PC should be able to handle chinese strings -------------- VB.NET ---------------- 'On the vb.net side (I am pretty sure, it is correct(?)) Dim oEncoderAnsi As System.Text.Encoding
2
6016
by: =?Utf-8?B?QWxleCBLLg==?= | last post by:
Hi all My TreeView has unicode and english labels. The treeview shows OK on the screen. When I am trying to get an item's label using TVM_GETITEM API message, the buffer returned by SendMessage always contains single-byte coded labels (ASCII) even though I use SendMessageW entry point. In other words, buffer is unicode string each character of which contains two ASCII letters of corresponding label.
5
1621
by: =?Utf-8?B?amM=?= | last post by:
Hello, This compiles OK using Multi-Byte character set, but when I switch to Unicode I get an error. char reply = _T("olleh"); I know this will fix the error with the Unicode compile, wchar_t reply = _T("olleh"); but this causes many other conversion problems in the program. Is there some other conversion macro that I could use instead of _T(),
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9179
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9116
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.