By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,960 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,960 IT Pros & Developers. It's quick & easy.

Using RichTextBox Read/Write Unicode File

P: n/a
This will be very helpfull for many!
Using RichTextBox Read/Write Unicode File

http://www.microsoft.com/indonesia/m...RichTextBox.as
p

Private Function ReadFile(ByVal myfile As String) As
String
Dim myFileStream As Stream = File.Open(myfile,
FileMode.Open)
Dim encoding As System.Text.Encoding =
System.Text.Encoding.UTF8
' Read string from binary file with UTF8 encoding
Dim bytes(1000) As Byte
Dim numBytesToRead As Integer = CInt
(myFileStream.Length)
'MessageBox.Show("Length = " & numBytesToRead)
Dim numBytesRead As Integer = 0
While numBytesToRead > 0
' Read may return anything from 0 to
numBytesToRead.
Dim n As Integer = myFileStream.Read(bytes,
numBytesRead, numBytesToRead)
MessageBox.Show("Number of bytes : " & n & " -
" & encoding.GetString(bytes))
If n = 0 Then ' We're at EOF
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While
myFileStream.Close()
'Dim buffer(30) As Byte
'binary_file.Read(buffer, 0, 30)
'MessageBox.Show(encoding.GetString(bytes))
Return encoding.GetString(bytes)
End Function

Private Function SaveFile(ByVal myfile As String) As
String
Dim myFileStream As Stream = File.Open(myfile,
FileMode.CreateNew)
Dim encoding As System.Text.Encoding =
System.Text.Encoding.UTF8
myFileStream.Write(encoding.GetBytes
(RichTextBox1.Text), 0, encoding.GetByteCount
(RichTextBox1.Text))
myFileStream.Close()
End Function

Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.