473,395 Members | 1,629 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,395 software developers and data experts.

Encoding of Text Files

Hi

Currently text file that I create are UTF-8 encoded and I need ANSI encoding
how can I do that
Thank you,
Samuel
Apr 4 '08 #1
4 1983
On Apr 4, 6:33*am, "Samuel" <samuel.shul...@ntlworld.comwrote:
Hi

Currently text file that I create are UTF-8 encoded and I need ANSI encoding
how can I do that

Thank you,
Samuel
IIRC System.Text.Encoding.Default maps to ANSI

///////////////////
Option Strict On

Imports System.IO
Imports System.Text

Module Module1

Sub Main()
Dim text As String = "hello, world"

Using stream As New
FileStream(Environment.GetFolderPath(Environment.S pecialFolder.Desktop)
& "/file.txt", FileMode.Create)
Dim bytes As Byte() = Encoding.Default.GetBytes(text)
stream.Write(bytes, 0, bytes.Length)
End Using
End Sub

End Module
/////////////

Thanks,

Seth Rowe [MVP]
Apr 4 '08 #2
"Samuel" <sa************@ntlworld.comschrieb:
Currently text file that I create are UTF-8 encoded and I need ANSI
encoding how can I do that
Specify the appropriate encoding in the 'StreamWriter' object's constructor.
'System.Text.Encoding.Default' will give you the system's Windows ANSI
codepage. 'System.Text.Encoding.GetEncoding(...)' will give you a certain
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/>

Apr 4 '08 #3
On Apr 4, 1:33*pm, "Samuel" <samuel.shul...@ntlworld.comwrote:
Hi

Currently text file that I create are UTF-8 encoded and I need ANSI encoding
how can I do that

Thank you,
Samuel
As previous posters suggested, System.Text.Encoding.Default will give
you chance of encoding your text in ANSI format. Also beware that
opening your text in notepad and saving with default encoding is done
in ANSI.
Apr 4 '08 #4
Thank you all

Samuel

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:1b**********************************@e67g2000 hsa.googlegroups.com...
On Apr 4, 1:33 pm, "Samuel" <samuel.shul...@ntlworld.comwrote:
Hi

Currently text file that I create are UTF-8 encoded and I need ANSI
encoding
how can I do that

Thank you,
Samuel
As previous posters suggested, System.Text.Encoding.Default will give
you chance of encoding your text in ANSI format. Also beware that
opening your text in notepad and saving with default encoding is done
in ANSI.
Apr 6 '08 #5

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

Similar topics

6
by: quincy | last post by:
I need help. Please bear with this. I have a program. It takes in files that are delimited. The delimiters are declared in the file by looking at fixed positions in the file (If you work with...
3
by: Gaia C via .NET 247 | last post by:
(Type your message here) Hi, I want to open a file to read from and then edit and write the text to another file. I am using StreamReader and StreamWriter for this purpose. The problem is that i...
2
by: jmhmaine | last post by:
During the course of development cycle I receive HTML files from designers that use Macs and PCs, but use tools other then Visual Studio. So these files sometimes are not UTF-8 Encoded. I see...
5
by: MattB | last post by:
I have the following function I use in my application quite a bit (I missed the VFP one and decided to make my own): Public Shared Function File2String(ByVal strFile) 'Open a file for reading...
15
by: Steven Bethard | last post by:
I'm having trouble using elementtree with an XML file that has some gbk-encoded text. (I can't read Chinese, so I'm taking their word for it that it's gbk-encoded.) I always have trouble with...
37
by: Zhiv Kurilka | last post by:
Hi, I have a text file with following content: "((^)|(.* +))§§§§§§§§" if I read it with: k=System.IO.StreamReader( "file.txt",System.Text.Encoding.ASCII); k.readtotheend()
4
by: A_StClaire_ | last post by:
hi, I am using the following code to download multiple file types from a server. .txt files transfer fine. however Word .doc files come through garbled and I don't know enough about encoding...
6
by: kath | last post by:
Hi all, Platform: winxp Version: Python 2.3 I have a task of reading files in a folder and creating an one excel file with sheets, one sheet per file, with sheet named...
1
by: ujjwaltrivedi | last post by:
Hey guys, Can anyone tell me how to create a text file with Unicode Encoding. In am using FileStream Finalfile = new FileStream("finalfile.txt", FileMode.Append, FileAccess.Write); ...
14
by: Zoro | last post by:
My task is to read html files from disk and save them onto SQL Server database field. I have created an nvarchar(max) field to hold them. The problem is that some characters, particularly html...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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...

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.