473,382 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

output ANSI encoding for unicode character

Hi,

I am trying to output a string of chinese characters as a
text file. When I open a file for writing from VB, the
file is automatically set to UTF-8 encoding (can tell by
opening the file from notepad). However, when I open
this file from a Chinese program that does not support
unicode, garbage is displayed. So what I have to do is
to first use Notepad to change the encoding of the file
to ANSI encoding, then the file would be displayed
correctly by the Chinese program.

What I would like to do is to directly output the chinese
text string in ANSI format so I don't need to go through
the extra step with notepad.

Could someone please advise?

Thanks!
Nov 20 '05 #1
4 18980
"Nick" <yk****@usc.edu> schrieb
I am trying to output a string of chinese characters as a
text file. When I open a file for writing from VB, the
file is automatically set to UTF-8 encoding (can tell by
opening the file from notepad). However, when I open
this file from a Chinese program that does not support
unicode, garbage is displayed. So what I have to do is
to first use Notepad to change the encoding of the file
to ANSI encoding, then the file would be displayed
correctly by the Chinese program.

What I would like to do is to directly output the chinese
text string in ANSI format so I don't need to go through
the extra step with notepad.

Could someone please advise?


I'm not sure if this is possible at all. I don't think so because the
unicode encoding can contain much more different characters than ANSI
encoding can. A general answer would be:

Dim fs As IO.FileStream
Dim MyChineseString As String = "<Chinese string>"
Dim sw As IO.StreamWriter

fs = New IO.FileStream( _
"g:\test.txt", IO.FileMode.CreateNew, _
IO.FileAccess.Write, IO.FileShare.Read _
)
sw = New IO.StreamWriter(fs, System.Text.Encoding.Default)
sw.WriteLine(MyChineseString)
sw.Close()
fs.Close()


--
Armin

Nov 20 '05 #2
Hi Nick,

I'm not sure if this'll help but,

Encoded text files have two bytes at the front which signify the encoding.
If you look at an encoded text file in NotePad, you won't see them. If you use
a hex editor, however, they will show up. If you can discover the two bytes
required for your text, you can fiddle the encoding by outputting these two
bytes first.

Regards,
Fergus
Nov 20 '05 #3
Cor
Nick,
My gues was that you need to set the culture information to do this, but I
made last times so much missers answering you, that I waited a while.
When you want me to help you with it say it, but I think that with some
thoughts of us you can do it yourself better.

Cor
Nov 20 '05 #4
Hick,
text file. When I open a file for writing from VB, the
file is automatically set to UTF-8 encoding (can tell by In addition to the others comments, it sounds like you are using the default
encoding when you are opening the file. How are you opening the file for
writing??

Remember that the default encoding for Streams in .NET is UTF-8.

If you specify a Chinese ANSI code page encoding when you open the file, the
file will be encoded as that ANSI code page.

Remember there are actually multiple ANSI code pages that a file could be
encoded to. You can use the System.Text.Encoding.Default encoding to use the
ANSI code page that your system is currently set to.

Imports System.IO
Imports System.Text

Dim writer As New StreamWriter("myfile.txt", False, Encoding.Default)

Or you can use Encoding.GetEncoding to specify a specific (Chinese) ANSI
code page.

Imports System.IO
Imports System.Text

' Chinese Simplified
Dim writer As New StreamWriter("myfile.txt", False,
Encoding.GetEncoding(54936))

Hope this helps
Jay

"Nick" <yk****@usc.edu> wrote in message
news:26****************************@phx.gbl... Hi,

I am trying to output a string of chinese characters as a
text file. When I open a file for writing from VB, the
file is automatically set to UTF-8 encoding (can tell by
opening the file from notepad). However, when I open
this file from a Chinese program that does not support
unicode, garbage is displayed. So what I have to do is
to first use Notepad to change the encoding of the file
to ANSI encoding, then the file would be displayed
correctly by the Chinese program.

What I would like to do is to directly output the chinese
text string in ANSI format so I don't need to go through
the extra step with notepad.

Could someone please advise?

Thanks!

Nov 20 '05 #5

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

Similar topics

5
by: Michael | last post by:
I mean how to use _tprintf().
6
by: dbaldi | last post by:
(this is follow-on message to one posted yesterday) I'm trying to reproduce the capabilities in both Notepad and Excel, whereby a Unicode text file with Unicode characters can be converted to...
1
by: lkrubner | last post by:
>Alan J. Flavell Oct 7 2004, 1:44 pm show options >>On Thu, 7 Oct 2004, Shmuel (Seymour J.) Metz wrote: >> at 08:24 PM, "Alan J. Flavell" <flav...@ph.gla.ac.uk> said: >> >I think you...
4
by: Richard | last post by:
I need to use ANSI encoding in VB.NET, but can't seem to find it, can anyone help, I can only find these ASCII UTF7 UTF8 default BigEndianUnicode Unicode, and a method getEncoding(codepage...
1
by: Mały Piotruœ | last post by:
Hello, Could you help me please with encoding transformations in .NET? I am beginner. I have some code that nearly works - but I have problem with converting from fileEncoding to Unicode (Strings...
10
by: Mark Rae | last post by:
Hi, I'm in the process if converting the data out of an old DOS-based SunAccounts system (don't ask!) into SQL Server. The data has been sent to me as a collection of hundreds of SunAccounts...
4
by: Antimon | last post by:
Hi, I need to convert a unicode string to ASCII. I can simply use getbytes method to do that but i would use some characters since Unicode is 16bit. But i thought there might be some way to...
9
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. ...
5
by: Les Caudle | last post by:
I've got some C# 2.0 code that has been working for a year. using (XmlWriter w = XmlWriter.Create("out.xml" ,settings)) { // many lines of code to write to w...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.