473,395 Members | 1,931 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.

EBCDIC Codepage file to Windows based file

Ram
Dear All,

Good Day

I am trying to convert a file which is generated on AS400 with codepage 00420 (arabic & English data combination) with no success. But using the same code( and changing 20420 to 708) I am able to convert a file from codepage ASMO 708 to windows based file and it is perfect. The following is the code I tried. i used 20420 codepage which is the nearest match for 00420. but no luck.

//Open file for reading and set encoding to 20420
StreamReader sr = new StreamReader((System.IO.Stream)File.OpenRead(strIn File ), Encoding.GetEncoding(20420));

//Openfile to write and set encoding to default

StreamWriter sw = new StreamWriter(strOutFile, false, Encoding.Default);

and I read the input file line by line and then write each line to the output file
//Read line
Line = sr.ReadLine();

//Loop logic here and then write to file

//Write line
sw.WriteLine(Line );

I verfied in windows regional settings to make sure that codepage 20420 is checked. Still I am not able to convert the file. The output is full of questions marks, which i belive is because it didnt recognize the character.

Anyone please help me to solve this issue.

Thanks in advance
Ram
Nov 16 '05 #1
4 7094
"Ram" <Ra*@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
Anyone please help me to solve this issue.


This might help: http://www.eggheadcafe.com/articles/20030521.asp
Nov 16 '05 #2
Ram <Ra*@discussions.microsoft.com> wrote:
I am trying to convert a file which is generated on AS400 with
codepage 00420 (arabic & English data combination) with no success.
But using the same code( and changing 20420 to 708) I am able to
convert a file from codepage ASMO 708 to windows based file and it is
perfect. The following is the code I tried. i used 20420 codepage
which is the nearest match for 00420. but no luck.

//Open file for reading and set encoding to 20420
StreamReader sr = new
StreamReader((System.IO.Stream)File.OpenRead(strIn File ),
Encoding.GetEncoding(20420));

//Openfile to write and set encoding to default

StreamWriter sw = new StreamWriter(strOutFile, false, Encoding.Default);

and I read the input file line by line and then write each line to
the output file
//Read line
Line = sr.ReadLine();

//Loop logic here and then write to file

//Write line
sw.WriteLine(Line );

I verfied in windows regional settings to make sure that codepage
20420 is checked. Still I am not able to convert the file. The output
is full of questions marks, which i belive is because it didnt
recognize the character.


Are you sure that all the characters in the file are available in
Encoding.Default?

I would suggest you separate the reading part from the writing part -
read some data and then write out the Unicode values you've read, eg

foreach (char c in line)
{
Console.WriteLine ((int)c);
}

Then look on www.unicode.org to see whether those are correct.

When you've got the reading of the data sorted, you can then move onto
trying to write it correctly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Ram
When you refer to Unicode Values i am confused. Is it because I am using 20420 encoding the string becomes unicode?

Now i am displaying the values, but which character mapping should i look in Unicode.org.

I am new to this codepage conversion stuff. If it is a basic question please excuse me.

Thanks & Regards
Ram

"Jon Skeet [C# MVP]" wrote:
Ram <Ra*@discussions.microsoft.com> wrote:
I am trying to convert a file which is generated on AS400 with
codepage 00420 (arabic & English data combination) with no success.
But using the same code( and changing 20420 to 708) I am able to
convert a file from codepage ASMO 708 to windows based file and it is
perfect. The following is the code I tried. i used 20420 codepage
which is the nearest match for 00420. but no luck.

//Open file for reading and set encoding to 20420
StreamReader sr = new
StreamReader((System.IO.Stream)File.OpenRead(strIn File ),
Encoding.GetEncoding(20420));

//Openfile to write and set encoding to default

StreamWriter sw = new StreamWriter(strOutFile, false, Encoding.Default);

and I read the input file line by line and then write each line to
the output file
//Read line
Line = sr.ReadLine();

//Loop logic here and then write to file

//Write line
sw.WriteLine(Line );

I verfied in windows regional settings to make sure that codepage
20420 is checked. Still I am not able to convert the file. The output
is full of questions marks, which i belive is because it didnt
recognize the character.


Are you sure that all the characters in the file are available in
Encoding.Default?

I would suggest you separate the reading part from the writing part -
read some data and then write out the Unicode values you've read, eg

foreach (char c in line)
{
Console.WriteLine ((int)c);
}

Then look on www.unicode.org to see whether those are correct.

When you've got the reading of the data sorted, you can then move onto
trying to write it correctly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4
Ram <Ra*@discussions.microsoft.com> wrote:
When you refer to Unicode Values i am confused. Is it because I am
using 20420 encoding the string becomes unicode?
Strings in .NET are *always* in Unicode.
Now i am displaying the values, but which character mapping should i
look in Unicode.org.
Look in http://www.unicode.org/charts and find the chart with the right
region of characters in. For instance, if you saw character 0x0785
you'd look down the list until you found
http://www.unicode.org/charts/PDF/U0780.pdf - unfortunately you
basically need to look at where the links go to work out which one to
follow.

I should have said before - it'll be easier for you if you print out
the values in hex, eg

Console.WriteLine ("{0:x}", (int)c);
I am new to this codepage conversion stuff. If it is a basic question
please excuse me.


It's hard to say whether it's a basic question or not at the moment :)

See http://www.pobox.com/~skeet/csharp/unicode.html for more
information though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

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

Similar topics

12
by: John Leslie | last post by:
I need to write a string to a file in EBCDIC. Do I need to do it character by character using a translation table, or is there a function to translate the whole string? (I am aware that I can...
6
by: R.A. | last post by:
Hi Is there some support for this file conversion in c#? Thanks
8
by: Chris H. | last post by:
Is there an easy way to convert a string that is in EBCDIC to ASCII
9
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
0
by: asklucas | last post by:
Hi there, I got an MS Access DB, which is causing problems when the client PC is running using a Traditional Chinese codepage. The DB was probably created with Access 97, Western European...
5
by: Tin Gherdanarra | last post by:
This is probably a fringe programme... In the past I used a C-program to convert from EBCDIC (CP500) to ASCII/Unicode. As you might guess, this is simply a 256-byte lookup table. I lifted it...
0
by: Guido/RM/ITALY | last post by:
Hi ! i need configure codepage for DB2 Connect. i have this environment: - DB2 Server on Z/OS with codepage 500 - DB2 Connect personal Edition 8.2 on Windows 2003 - connection to DB2 via...
4
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hi, I have read the "how to's" on MSDN including this one, http://msdn2.microsoft.com/en-us/library/36b93480.aspx, on reading/writing files in C#, but haven't found something that I can put...
44
by: Pilcrow | last post by:
Is there a way that a proram can detect whether it is operating in an ASCII or an EBCDIC environment?
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?
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
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,...
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...
0
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...
0
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,...

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.