473,563 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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((S ystem.IO.Stream )File.OpenRead( strInFile ), Encoding.GetEnc oding(20420));

//Openfile to write and set encoding to default

StreamWriter sw = new StreamWriter(st rOutFile, false, Encoding.Defaul t);

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(Li ne );

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 7114
"Ram" <Ra*@discussion s.microsoft.com > wrote in message
news:3B******** *************** ***********@mic rosoft.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*@discussion s.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((S ystem.IO.Stream )File.OpenRead( strInFile ),
Encoding.GetEnc oding(20420));

//Openfile to write and set encoding to default

StreamWriter sw = new StreamWriter(st rOutFile, false, Encoding.Defaul t);

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(Li ne );

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.Defaul t?

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.WriteLi ne ((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.co m>
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*@discussion s.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((S ystem.IO.Stream )File.OpenRead( strInFile ),
Encoding.GetEnc oding(20420));

//Openfile to write and set encoding to default

StreamWriter sw = new StreamWriter(st rOutFile, false, Encoding.Defaul t);

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(Li ne );

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.Defaul t?

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.WriteLi ne ((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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4
Ram <Ra*@discussion s.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.WriteLi ne ("{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.co m>
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
4626
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 convert a whole file using Unix utilities, but this file will have only a few header records in EBCDIC)
6
925
by: R.A. | last post by:
Hi Is there some support for this file conversion in c#? Thanks
8
17929
by: Chris H. | last post by:
Is there an easy way to convert a string that is in EBCDIC to ASCII
9
6742
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 get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger...
0
1815
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 codepage. However, the DB I got is now already in Access 2002 / 2003 file format, thus should be already converted to Unicode. When I open the DB on...
5
3726
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 from Larry Wall's perl source, to be found here: http://www.nntp.perl.org/group/perl.mvs/735 This worked very well. For some reason, the C# codec...
0
2204
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 JDBC for java application that run in windows
4
6511
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 together that is working. The file I have is in EBCDIC, rec length = 250 and delimited by CRLF's. What I want to do is open an EBCDIC file in...
44
3832
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
7583
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...
0
7885
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. ...
0
8106
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...
1
7638
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5484
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...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.