473,547 Members | 2,553 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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim enc As System.Text.Enc oding = System.Text.Enc oding.Unicode

Dim a As String =
Microsoft.Visua lBasic.FileIO.F ileSystem.ReadA llText("01.bin" , enc)

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

Microsoft.Visua lBasic.FileIO.F ileSystem.Write AllText("02.bin ", b,
False, enc)

End Sub
Apr 15 '06 #1
4 1847
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***@discussi ons.microsoft.c om> schreef in bericht
news:1F******** *************** ***********@mic rosoft.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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim enc As System.Text.Enc oding = System.Text.Enc oding.Unicode

Dim a As String =
Microsoft.Visua lBasic.FileIO.F ileSystem.ReadA llText("01.bin" , enc)

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

Microsoft.Visua lBasic.FileIO.F ileSystem.Write AllText("02.bin ", b,
False, enc)

End Sub

Apr 15 '06 #2
"kenny" <ke***@discussi ons.microsoft.c om> 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.Unico de' 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.Unico de' 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***@discussi ons.microsoft.c om> 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.Unico de' 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
17598
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 that - opens a file appropriately for output - writes to this file Thanks very much. Michael Weir
4
6047
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 script that grabs some web pages from the web, regex parse the data and stores it localy to xml file for further use.. at first i had no problem using...
3
24488
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 for decrypting the file works fine however when I encrypt the file, several characters are corrupted. when I looked into it they are always extended...
9
13404
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. But the open() on ifstream only takes char * strings (mbcs?). In old iostreams, I could _wopen() the file, get the filedesc, and call attach() on...
10
8024
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
6
7008
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 file just fine. If I set it up as ASCII, it reads a non-unicode text file. But I don't know the file format in advance. How can my app determine...
24
3349
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 without 'utf8' in it, then things start to go downhill: 2a. The app assumes unicode objects internally. i.e. Whenever there is
1
3850
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 parser and dbi/ odbc for my db connection. To fix problems with unicode I built a work-around by mapping unicode characters to equivalent ascii...
7
1634
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 of a sudden, it is reading a straight text file and adding a null after each character it reads in. Why is that? The original file doesn't have...
0
7510
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7463
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7797
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6032
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3493
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1923
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 we have to send another system
0
748
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.