Re: Unicode Character Issue
- From: Joergen Bech <jbech<NOSPAM>@<NOSPAM>post1.tele.dk>
- Date: Wed, 04 Jun 2008 18:43:55 +0200
Here is a small, working example. Disregard
the ReadBinary stuff. That was just something
from another project and could be written
smaller/cleaner/etc.
Regards,
Joergen Bech
---snip---
Option Explicit On
Option Strict On
Imports System.IO
Imports System.Text
Imports System
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ansi() As Byte = ReadBinary("d:\ansi.txt")
Dim s As String =
Encoding.GetEncoding("iso-8859-1").GetString(ansi)
TextBox1.Text = s
' Dim sb As New StringBuilder
' For Each b As Byte In ansi
' sb.Append(Chr(b))
' Next
' TextBox1.Text = sb.ToString
End Sub
Public Shared Function ReadBinary(ByVal file As String) As Byte()
Dim errorInformation As String = String.Empty
Dim result As Byte() = ReadBinary(file, errorInformation)
If String.IsNullOrEmpty(errorInformation) Then
Return result
Else
Throw New IOException(errorInformation)
End If
End Function
Public Shared Function ReadBinary(ByVal file As String, _
ByRef errorInformation As
String) As Byte()
Try
Dim fInfo As New FileInfo(file)
Dim numBytes As Long = fInfo.Length
Dim fStream As New FileStream(file, FileMode.Open,
FileAccess.Read)
Dim br As New BinaryReader(fStream)
Dim data() As Byte = br.ReadBytes(CInt(numBytes))
br.Close()
fStream.Close()
Return data
Catch ex As Exception
errorInformation = ex.Message
Return Nothing
End Try
End Function
On Wed, 4 Jun 2008 17:04:48 +0100, "Samuel"
<samuel.shulman@xxxxxxxxxxxx> wrote:
Hi
I am trying to read text files that are saved in ANSI format with Unicode
characters such as French e German big S etc, and as I read the file these
characters appear as squares etc.
I know that if the file would be saved as Unicode this wouldn't be a
problem.
The question is whether there is an option that when I create the Stream
Reader the application will recognize it as Unicode characters.
Thank you,
Samuel
.
- References:
- Unicode Character Issue
- From: Samuel
- Unicode Character Issue
- Prev by Date: Re: Environment.UserName
- Next by Date: Re: SaveFileDialog.ShowDialog() returns Cancel when Yes to overwrite ...
- Previous by thread: Re: Unicode Character Issue
- Next by thread: Re: Unicode Character Issue
- Index(es):
Relevant Pages
|