473,473 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using RichTextBox Read/Write Unicode File

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
0 5629

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
2
by: hezhenjie | last post by:
Hi, all: I just need to parse a unicode file, and assume to get data one line by one line. I use _wfopen(), fgetws(), wcslen(), wcsstr(), making it work normally on Windows platform. However,...
10
by: Tibby | last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file. -- Thanks --- Outgoing mail is certified Virus...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
0
by: iwdu15 | last post by:
hi, im creating an instant messenger using TCP sockets, and everythings been fine until now. i want to be able to send rich text, but im hitting a wall here. what i want to do is send the font...
2
by: starffly | last post by:
I want to read a xml file in Unicode, UTF-8 or a native encoding into a wchar_t type string, so i write a routine as follows, however, sometimes a Unicode file including Chinese character cannot...
8
by: Rui Maciel | last post by:
I've just started learning how to use the wchar_t data type as the basis for Unicode strings and unfortunately I'm having quite a bit of problems, both in the C front and the Unicode front. In...
3
by: Ellie | last post by:
I have a VB6 program upgraded to vb.net and I need to use the printline function to write to a text file but I need certain characters in bold. Would anyone be able to tell me how to do this, if...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.