473,408 Members | 2,832 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,408 software developers and data experts.

code page problem

Hi,

I'm developing an application that reads data from a file. The data has been
encoded using code page 850.
I use the FileOpen function to open the file and the FileGet function to
read the records, but the string I read is encoded using code page 1252.

Is there a way to specify the codepage before reading the data, or do I have
to convert every string I find ?
I've found a sample of convertion function in the help, but it slows down my
application:

Protected Function ConvertString(ByVal str As String) As String
Dim enc As System.text.Encoding =
System.Text.Encoding.GetEncoding(850)
Dim encw As System.text.Encoding =
System.Text.Encoding.GetEncoding(1252)

' Convert the string into a byte[].
Dim wBytes As Byte() = encw.GetBytes(str)

' Perform the conversion from one encoding to the other.
Dim bytes As Byte() = System.Text.Encoding.Convert(enc, encw,
wBytes)

' Convert the new byte[] into a char[] and then into a string.
' This is a slightly different approach to converting to illustrate
' the use of GetCharCount/GetChars.
Dim asciiChars(encw.GetCharCount(bytes, 0, bytes.Length)) As Char
encw.GetChars(bytes, 0, bytes.Length, asciiChars, 0)
Dim asciiString As New String(asciiChars)

Return asciiString
End Function

Thanks for your help

David
Nov 20 '05 #1
2 1929
Hi David,

You can use StreamReader which allow for specifying the source encoding upon
instance construction.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"David Scemama" <da***********@nospam.wanadoo.fr> wrote in message
news:uy*************@TK2MSFTNGP11.phx.gbl...
Hi,

I'm developing an application that reads data from a file. The data has been encoded using code page 850.
I use the FileOpen function to open the file and the FileGet function to
read the records, but the string I read is encoded using code page 1252.

Is there a way to specify the codepage before reading the data, or do I have to convert every string I find ?
I've found a sample of convertion function in the help, but it slows down my application:

Protected Function ConvertString(ByVal str As String) As String
Dim enc As System.text.Encoding =
System.Text.Encoding.GetEncoding(850)
Dim encw As System.text.Encoding =
System.Text.Encoding.GetEncoding(1252)

' Convert the string into a byte[].
Dim wBytes As Byte() = encw.GetBytes(str)

' Perform the conversion from one encoding to the other.
Dim bytes As Byte() = System.Text.Encoding.Convert(enc, encw,
wBytes)

' Convert the new byte[] into a char[] and then into a string.
' This is a slightly different approach to converting to illustrate ' the use of GetCharCount/GetChars.
Dim asciiChars(encw.GetCharCount(bytes, 0, bytes.Length)) As Char
encw.GetChars(bytes, 0, bytes.Length, asciiChars, 0)
Dim asciiString As New String(asciiChars)

Return asciiString
End Function

Thanks for your help

David


Nov 20 '05 #2
I'm using FileGet because I'm reading records and using it, I directly get
the records filled after reading.
Is there a way to do the same using streamreader ?
David

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:eI**************@TK2MSFTNGP09.phx.gbl...
Hi David,

You can use StreamReader which allow for specifying the source encoding upon instance construction.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"David Scemama" <da***********@nospam.wanadoo.fr> wrote in message
news:uy*************@TK2MSFTNGP11.phx.gbl...
Hi,

I'm developing an application that reads data from a file. The data has been
encoded using code page 850.
I use the FileOpen function to open the file and the FileGet function to
read the records, but the string I read is encoded using code page 1252.

Is there a way to specify the codepage before reading the data, or do I

have
to convert every string I find ?
I've found a sample of convertion function in the help, but it slows down my
application:

Protected Function ConvertString(ByVal str As String) As String
Dim enc As System.text.Encoding =
System.Text.Encoding.GetEncoding(850)
Dim encw As System.text.Encoding =
System.Text.Encoding.GetEncoding(1252)

' Convert the string into a byte[].
Dim wBytes As Byte() = encw.GetBytes(str)

' Perform the conversion from one encoding to the other.
Dim bytes As Byte() = System.Text.Encoding.Convert(enc, encw,
wBytes)

' Convert the new byte[] into a char[] and then into a string.
' This is a slightly different approach to converting to

illustrate
' the use of GetCharCount/GetChars.
Dim asciiChars(encw.GetCharCount(bytes, 0, bytes.Length)) As

Char encw.GetChars(bytes, 0, bytes.Length, asciiChars, 0)
Dim asciiString As New String(asciiChars)

Return asciiString
End Function

Thanks for your help

David

Nov 20 '05 #3

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

Similar topics

14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
8
by: David D. | last post by:
In html, one can say <script language="JavaScript" src="http://someCodeSnippet.js"> Is there any way to embed the included code snippet in a function (in the case where it is not already a...
10
by: CSDunn | last post by:
Hello, I'm having a problem with ASP.NET using IIS 5.1 on a Windows XP Pro machine. ASP.NET will not process the following code: ******************************* <html> <head> </head> <body>...
1
by: D A H | last post by:
I have gotten the same exception in multiple projects. I have solved the underlying problem. My question is if anyone knew of a setting that would cause this exception to be thrown. A...
10
by: Don Munroe | last post by:
This one has me stumped. I have three web applications running on two different servers. The first that works fine is hosted by a .Net hosting company. Everyone that uses it has no problems...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
1
by: Bill | last post by:
Does anyone know how to fix this problem? On form submittal I'm getting the following error in Visual Studio 2005: The state information is invalid for this page and might be corrupted....
7
by: Mike Rand | last post by:
I am having a really hard time trying to get some client side code hooked up in VS2005, ASP 2.0. The code is in an .inc file (vbscript). The first problem I am encountering is the ASP.NET page...
13
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.