473,756 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(B yVal str As String) As String
Dim enc As System.text.Enc oding =
System.Text.Enc oding.GetEncodi ng(850)
Dim encw As System.text.Enc oding =
System.Text.Enc oding.GetEncodi ng(1252)

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

' Perform the conversion from one encoding to the other.
Dim bytes As Byte() = System.Text.Enc oding.Convert(e nc, 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(b ytes, 0, bytes.Length)) As Char
encw.GetChars(b ytes, 0, bytes.Length, asciiChars, 0)
Dim asciiString As New String(asciiCha rs)

Return asciiString
End Function

Thanks for your help

David
Nov 20 '05 #1
2 1957
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******** *****@TK2MSFTNG P11.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(B yVal str As String) As String
Dim enc As System.text.Enc oding =
System.Text.Enc oding.GetEncodi ng(850)
Dim encw As System.text.Enc oding =
System.Text.Enc oding.GetEncodi ng(1252)

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

' Perform the conversion from one encoding to the other.
Dim bytes As Byte() = System.Text.Enc oding.Convert(e nc, 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(b ytes, 0, bytes.Length)) As Char
encw.GetChars(b ytes, 0, bytes.Length, asciiChars, 0)
Dim asciiString As New String(asciiCha rs)

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.c om> wrote
in message news:eI******** ******@TK2MSFTN GP09.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******** *****@TK2MSFTNG P11.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(B yVal str As String) As String
Dim enc As System.text.Enc oding =
System.Text.Enc oding.GetEncodi ng(850)
Dim encw As System.text.Enc oding =
System.Text.Enc oding.GetEncodi ng(1252)

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

' Perform the conversion from one encoding to the other.
Dim bytes As Byte() = System.Text.Enc oding.Convert(e nc, 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(b ytes, 0, bytes.Length)) As

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

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
2619
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 (that part's not here -- spotlighting the problem code): --------BEGIN CODE PAGE------------ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
53
5741
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 difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
8
2580
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 function in the remote souce file)? - David D.
10
1337
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> <form method= "post" runat="server"> <asp:Label id=lblHelloWorld text="HelloWorld" runat=Server />
1
1897
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 codeveloper on the same project can get a copy of the project from VSS and does not get this exception, ever. I do. We both have the code that causes this exception to be thrown. We do NOT checkin our
10
1840
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 hitting the site. The other two applications are running on my personal server which has Windows 2003, IIS 6, and .Net 1.1 Most of my users can use the sites. Two have come up with a very strange problem. They try to go to either application and...
171
7772
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) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
1
3452
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. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: The state...
7
1611
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 doesn't like vbscript and throws fits about the syntax. Second, the page throws fits about the server side code tags (<% ... %>),...are these supported anymore? Third, when I set the onclick event of a client side HTML button it does not recognize...
13
3558
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 some javascript code that calls window.open. I pass the resource url of page B to Page A's window.open call. Page B is then loaded and executed but none of the server-side code is rendered. If I view the source of the page, the code (and page...
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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
10034
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
9872
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...
1
9843
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
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
8713
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
7248
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...
3
2666
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.