473,503 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing a Unicode String into file

Hello,
I am trying to read the contents of 01.bin (unicode) into a String, to
modify it and finally to write it back into an other file named 02.bin.

If the file really contains "a b c", then everything is replaced properly.
But the finally output looks like "ÿþb b c".
There is that prefix ÿþ. I assume that it is always printed when you work
with unicode files but I do not know how to get rid of it.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim enc As System.Text.Encoding = System.Text.Encoding.Unicode

Dim a As String =
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllTex t("01.bin", enc)

Dim b As String = Replace(a, "abc", "bbc", 1, -1)

Microsoft.VisualBasic.FileIO.FileSystem.WriteAllTe xt("02.bin", b,
False, enc)

End Sub
Apr 15 '06 #1
4 1843
Kenny,

I think that you first have to decide in what code your outputfile should
be.

Some links,

General
http://www.microsoft.com/globaldev/r...ce/cphome.mspx

OS systems
http://www.microsoft.com/globaldev/r...ocversion.mspx

I hope this helps a little bit?

Cor

"kenny" <ke***@discussions.microsoft.com> schreef in bericht
news:1F**********************************@microsof t.com...
Hello,
I am trying to read the contents of 01.bin (unicode) into a String, to
modify it and finally to write it back into an other file named 02.bin.

If the file really contains "a b c", then everything is replaced properly.
But the finally output looks like "ÿþb b c".
There is that prefix ÿþ. I assume that it is always printed when you work
with unicode files but I do not know how to get rid of it.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim enc As System.Text.Encoding = System.Text.Encoding.Unicode

Dim a As String =
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllTex t("01.bin", enc)

Dim b As String = Replace(a, "abc", "bbc", 1, -1)

Microsoft.VisualBasic.FileIO.FileSystem.WriteAllTe xt("02.bin", b,
False, enc)

End Sub

Apr 15 '06 #2
"kenny" <ke***@discussions.microsoft.com> schrieb:
I am trying to read the contents of 01.bin (unicode) into a String, to
modify it and finally to write it back into an other file named 02.bin.

If the file really contains "a b c", then everything is replaced properly.
But the finally output looks like "ÿþb b c".
There is that prefix ÿþ. I assume that it is always printed when you work
with unicode files but I do not know how to get rid of it.


It's the UTF-BOM. 'Encoding.Unicode' is actually UTF-16. You can avoid
creating the BOM as follows:

\\\
Dim enc As Encoding = New UnicodeEncoding(True, False)
Dim sw As New StreamWriter(..., enc)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 15 '06 #3
thank you! it works.

@Cor Ligthert:
i think it should be Unicode :)

"Herfried K. Wagner [MVP]" wrote:
It's the UTF-BOM. 'Encoding.Unicode' is actually UTF-16. You can avoid
creating the BOM as follows:

\\\
Dim enc As Encoding = New UnicodeEncoding(True, False)
Dim sw As New StreamWriter(..., enc)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 15 '06 #4

Do you (or others) know, by chance, if there is also a way to avoid
insertion of the Byte Order Mark (BOM), using the binary formatter? I
have alway been curious about that....

-tom

Herfried K. Wagner [MVP] ha scritto:
"kenny" <ke***@discussions.microsoft.com> schrieb:
I am trying to read the contents of 01.bin (unicode) into a String, to
modify it and finally to write it back into an other file named 02.bin.

If the file really contains "a b c", then everything is replaced properly.
But the finally output looks like "ÿþb b c".
There is that prefix ÿþ. I assume that it is always printed when you work
with unicode files but I do not know how to get rid of it.


It's the UTF-BOM. 'Encoding.Unicode' is actually UTF-16. You can avoid
creating the BOM as follows:

\\\
Dim enc As Encoding = New UnicodeEncoding(True, False)
Dim sw As New StreamWriter(..., enc)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Apr 16 '06 #5

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

Similar topics

3
17594
by: Michael Weir | last post by:
I'm sure this is a very simple thing to do, once you know how to do it, but I am having no fun at all trying to write utf-8 strings to a unicode file. Does anyone have a couple of lines of code...
4
6040
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
3
24483
by: JSM | last post by:
Hi, I am just trying to port an existing simple encryption routine to C#. this routine simply adds/substracts 10 ascii characters to each character in a text file (except quotes). The routine...
9
13403
by: Charles F McDevitt | last post by:
I'm trying to upgrade some old code that used old iostreams. At one place in the code, I have a path/filename in a wchar_t string (unicode utf-16). I need to open an ifstream to that file. ...
10
8011
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
6
7001
by: Jeff | last post by:
Hi - I'm setting up a streamreader in a VB.NET app to read a text file and display its contents in a multiline textbox. If I set it up with System.Text.Encoding.Unicode, it reads a unicode...
24
3339
by: Donn Ingle | last post by:
Hello, I hope someone can illuminate this situation for me. Here's the nutshell: 1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale. 2. If this returns "C" or anything...
1
3845
by: Mudcat | last post by:
In short what I'm trying to do is read a document using an xml parser and then upload that data back into a database. I've got the code more or less completed using xml.etree.ElementTree for the...
7
1633
by: tshad | last post by:
I have a program in 2005 that is reading a text file removing text and then writing it back out again. It removes lines that start with PRINT. This program has worked fine for months. Now all...
0
7205
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
7093
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
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7349
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...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4688
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
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.