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 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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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>...
|
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...
|
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...
|
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)...
|
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....
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |