D
David Scemama
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 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