Read File Bytes into String

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
bisnes_niko
Serious Programmer
Serious Programmer
Posts: 409
Joined: Tue Aug 24, 2010 1:21 pm

Read File Bytes into String
bisnes_niko
Hi, I been having a pain in the butt to find out how could I load and read bytes into string the notepad way.

I know already howto bind data into an existing file.

This is how I would like to get it:
needhelp.png
All you gotta do is to find how can I load data into strings notepad way. Thank you, bye.

REWARD = 50 Credits
You do not have the required permissions to view the files attached to this post.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Read File Bytes into String
mandai
You could encode it into a hex string:
Code: Select all
        Dim bytes As Byte() = IO.File.ReadAllBytes("file.exe")
        Dim encoded As String = ""
        For i As Integer = 0 To bytes.Length - 1
            encoded += bytes(i).ToString("X2")
        Next
        MsgBox(encoded)
Then to convert that string back to binary you can use:
Code: Select all
        Dim newBytes As List(Of Byte) = New List(Of Byte)
        For i As Integer = 0 To encoded.Length - 1 Step 2
            Dim current As Byte = Byte.Parse(encoded.Substring(i, 2), NumberStyles.AllowHexSpecifier)
            newBytes.Add(current)
        Next
        Dim decoded As Byte() = newBytes.ToArray()
15/6/11 Edit: Improved efficiency.
Last edited by mandai on Wed Jun 15, 2011 5:50 pm, edited 4 times in total.
User avatar
bisnes_niko
Serious Programmer
Serious Programmer
Posts: 409
Joined: Tue Aug 24, 2010 1:21 pm

Re: Read File Bytes into String
bisnes_niko
I'm sorry, but thats not I need. I need to read bytes into for an example textbox like MS Notepad does. Thats how I could find & read data I put there like Hello World

I already know how to bind text end of the file and it would still work
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Read File Bytes into String
mandai
Notepad displays the file as a character array, not a byte array.
4 posts Page 1 of 1
Return to “Tutorial Requests”