473,654 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1995
On Apr 4, 6:33*am, "Samuel" <samuel.shul... @ntlworld.comwr ote:
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.Enc oding.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(Envi ronment.GetFold erPath(Environm ent.SpecialFold er.Desktop)
& "/file.txt", FileMode.Create )
Dim bytes As Byte() = Encoding.Defaul t.GetBytes(text )
stream.Write(by tes, 0, bytes.Length)
End Using
End Sub

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

Thanks,

Seth Rowe [MVP]
Apr 4 '08 #2
"Samuel" <sa************ @ntlworld.comsc hrieb:
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.En coding.Default' will give you the system's Windows ANSI
codepage. 'System.Text.En coding.GetEncod ing(...)' 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.comwr ote:
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.Enc oding.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

"kimiraikko nen" <ki************ *@gmail.comwrot e in message
news:1b******** *************** ***********@e67 g2000hsa.google groups.com...
On Apr 4, 1:33 pm, "Samuel" <samuel.shul... @ntlworld.comwr ote:
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.Enc oding.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
1570
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 ANSI x12 files, you know what I mean). This normally isn't a problem, but I'm getting a file that is using some odd characters as delimiters. Specifically, a Hex 'BA' is declared as a delimiter. I
3
15440
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 don't know the encoding of the file, because it can be saved at any encoding. When using the stream objects it is using the UTF-8 encoding, and therefore after editting the file, some characters are omitted. How can i know the file encoding? or any...
2
4354
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 that Visual Studio creates a globalization tag with UTF-8 as the requestEndcoding and responseEncoding. I have three questions regarding this: 1. Does the globalization tag convert an ANSI encoded file into UTF-8 when it complies the ASPX and...
5
1657
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 Dim strFilename As String = strFile 'Get a StreamReader class that can be used to read the file Dim objStreamReader As System.IO.StreamReader Try
15
5415
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 encodings, so I'm sure I'm just screwing something simple up. Can anyone help me? Here's the interactive session. Sorry it's a little verbose, but I figured it would be better to include too much than not enough. I basically expected...
37
3367
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
2034
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 to understand why. the object 's' is a Mentalis.org component that, for all purposes here, is a System.Net.Socket. the line I commented out is one that hard-codes the encoding to 'ASCII' which I assume would only hurt me.
6
3092
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 as filename. I am facing problem in handling special characters. I am using XLRD and XLW package to read/write from/to file. But facing problem in handling special characters. I am getting encode error.
1
32899
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); ###Question: Now this creates finalfile.txt with ANSI Encoding ...which is a default. Either tell me how to change the default or how to create a
14
5755
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 entities, and French/German special characters are lost and/or replaced by a question mark. This is really frustrating. I have tried using StreamReader with ALL the encodings available and none work correctly. Each encoding handles some characters...
0
8294
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
8816
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
8709
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...
0
8596
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...
0
7309
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.