Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 30th, 2009, 07:40 AM
Authorized User
Join Date: Jan 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Converting ASCII Text file to Unicode

The problem i am having is that i have to process CSV files into the database. My CSV files are in ASCII format as provided by customer. These files can contain german characters so therefor i need to save these in unicode format so that i can read them and update in SQLServer.
Currently what i do is that i open the CSV file and save it in Unicode format manually and all processing is done alright. What i have to do is to write an application which will process these files automatically. So want the saving to be done by the application.
I am using C#.Net as my programming language.
I have searched the web and different forums for this. The solution that most of the forums have provided is to use StreamReader and StreamWriter classes and use Encoding.unicode or Encoding.UTF-8. The file is saved alright but german characters are still not been converted to unicode.
I have tried almost all ways i found on internet for this purpose to try saving file in unicode but havent succeeded yet.
Will any body tell me that what mistake i am making that german characters are not been converted to unicode.
Old July 2nd, 2009, 07:40 AM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

The ASCII standard only contains 128 characters, therefore what you are calling an 'ASCII' file is not. You are probably referring to ISO 8859-1 (commonly known as 'Latin-1') which contains all the latin characters required to write the german language.

The thing is, unicode is a superset of both ASCII and ISO 8859-1, so in theory a valid ASCII file is also a valid unicode (UTF-8) file.

UTF-16 and UTF-32 are different in the way they represent their characters, so would not be valid ASCII documents.

Without seeing the files in question it is hard to make any further comments.
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Old July 16th, 2009, 07:45 AM
Authorized User
Join Date: Jan 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem Reading the unicode file

Thanks Sam for reply. I have that problem solved. I had no problem in saving the file. File was saved alright. Problem was when i was reading the file. When reading i was using System.IO.File.ReadAllText method. There it was problem. I specified Encoding.Default when reading the file and it succeded.

Similar Threads
Thread Thread Starter Forum Replies Last Post
unicode and ascii characters sudhanshu631 BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 0 May 24th, 2009 12:15 PM
Converting Int -> ASCII silaros C++ Programming 1 June 5th, 2007 01:12 AM
Get UNICODE or ASCII Value of a character Eyob_the_pro C# 0 January 10th, 2007 03:42 AM
Write ASCII text file muklee C# 1 December 12th, 2004 09:40 PM
Reading ASCII data from text file. LordBeholder VB How-To 2 June 25th, 2004 05:50 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.