Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Two functions into one
Message
From
27/06/2006 12:04:39
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
27/06/2006 11:56:52
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01131998
Message ID:
01132062
Views:
14
>>myString = BitConverter.ToString(loByte)
>>
>>PS: Sorry not this one. Hang on:)
>>
>>
>>Private Function UnicodeBytesToString( _
>>    ByVal bytes() As Byte) _
>>    As String
>>
>>    Return System.Text.Encoding.Unicode.GetString(bytes)
>>End Function
>>
>
>Based on that, if I use this:
>
>
>        Dim lcText As String = ""
>        lcText = FileToStr("D:\Logo.jpg")
>        MessageBox.Show(lcText.Length.ToString)
>        oApp.CreateFile(lcText, "D:\Logo2.jpg")
>
>    End Sub
>
>    ' FileToStr() VFP equivalent
>    ' expC1 File name
>    Public Function FileToStr(ByVal tcFileName As String) As String
>        Dim loBinaryReader As IO.BinaryReader
>        Dim loByte() As Byte
>        Dim loFileStream As IO.FileStream
>        Dim lcString As String = ""
>        Try
>            loFileStream = New IO.FileStream(tcFileName, FileMode.Open, FileAccess.Read)
>            loBinaryReader = New IO.BinaryReader(loFileStream)
>            loByte = loBinaryReader.ReadBytes(CType(loFileStream.Length, Integer))
>            lcString = UnicodeBytesToString(loByte)
>            loBinaryReader.Close()
>            loFileStream.Close()
>        Catch loError As Exception
>            System.Windows.Forms.MessageBox.Show(loError.Message)
>            lcString = ""
>        End Try
>        Return lcString
>    End Function
>
>    Private Function UnicodeBytesToString(ByVal bytes() As Byte) As String
>        Return System.Text.Encoding.Unicode.GetString(bytes)
>    End Function
>
>
>My logo.jpg is 35k. After the conversion back Logo2.jpg, I end up with a 17k file.

But for a jpg you shouldn't do a conversion. IOW remove conversion from code. Just write it out with BinaryWriter (might do with text as well).
PS:UnicodeEncoding was sample and you might use other encodings' GetString() method too. Unicode is 2 bytes per character.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform