Re: Unicode Character Issue

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




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


.



Relevant Pages

  • Re: zebra Printer
    ... Public pOutputFile As String ... Public Shared Function ClosePrinterAs ... Dim ByteBuf As Integer ... Public Function GetPrinterStatusText(ByVal PI2Status As Long) As ...
    (microsoft.public.dotnet.languages.vb)
  • Re: zebra Printer
    ... Public pOutputFile As String ... Public Shared Function ClosePrinterAs ... Dim ByteBuf As Integer ... Public Function GetPrinterStatusText(ByVal PI2Status As Long) As ...
    (microsoft.public.dotnet.languages.vb)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Re: MBR vs. MBV
    ... > Public Shared Function GetPayablesConnection() As AdsConnection ... > Dim daVendors As New AdsDataAdapter ... >Public Shared Function GetVendor(ByVal VendorID As Integer) As Vendor ... > Private sName As String ...
    (microsoft.public.dotnet.framework.remoting)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)