473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

gw.Write(string) ?

I am getting an extra character at te beginning of the file,
can someone please check if there is an error in my code?

Dim fs As FileStream
fs = New FileStream(Form1.REGFILE, FileMode.CreateNew, FileAccess.Write)
Dim gw As New BinaryWriter(fs)
gw.Write(s)
gw.Flush()
gw.Close()
fs.Close()
Nov 21 '05 #1
4 1089
"dinny" <nospam> schrieb:
I am getting an extra character at te beginning of the file,
can someone please check if there is an error in my code?

Dim fs As FileStream
fs = New FileStream(Form1.REGFILE, FileMode.CreateNew, FileAccess.Write)
Dim gw As New BinaryWriter(fs)
gw.Write(s)
gw.Flush()
gw.Close()
fs.Close()


Maybe the character is an UTF BOM:

<URL:http://www.unicode.org/faq/utf_bom.html>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2
Dinny,
Review the help for BinaryWriter.Write(String)!

Seeing as BinaryWriter is writing a Binary File, it encodes the length of
the string before it writes the encoded characters of the string. It does
this so as to allow reading back the same number of characters in
BinaryReader.ReadString.

For information on the encoded length see the following:

BinaryWriter.Write(String):
http://msdn.microsoft.com/library/de...iteTopic13.asp
Corresponding BinaryReader.ReadString:
http://msdn.microsoft.com/library/de...tringTopic.asp

Hope this helps
Jay
"dinny" <nospam> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am getting an extra character at te beginning of the file,
can someone please check if there is an error in my code?

Dim fs As FileStream
fs = New FileStream(Form1.REGFILE, FileMode.CreateNew, FileAccess.Write)
Dim gw As New BinaryWriter(fs)
gw.Write(s)
gw.Flush()
gw.Close()
fs.Close()

Nov 21 '05 #3
For process text. Suggest use StreamWriter to replace BinaryWriter.

Nov 21 '05 #4
Thanks very much.
Nov 21 '05 #5

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

Similar topics

4
by: marslee | last post by:
How to write data in a file to the next line fwrite($ourFileHandle , $_POST); fwrite($ourFileHandle , "\n"); fwrite($ourFileHandle , $_POST); I want the following output Peter Main.st
6
by: Mark Anderson | last post by:
I have code to develop result page links (like a search engine) for some results being passed from a database where I've no server-sdide acces - thus JS. The code is below and works fine except...
2
by: Von Shean | last post by:
I use the following code to format the numbers to have commas. But in case when input is zero it returns an empty string....any ideas? String.Format("{0:#,###.##}",dblNum);
5
by: Mullin Yu | last post by:
i want to build an application of both gui and batch interface by using windows application project. i check either passing any args or not. if no, then open the gui application. if yes, use the...
2
by: roopeman | last post by:
i need your help, my code as below : //----------------------------------------------------------------------- //Wrote by Michael April 30 2005...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
5
by: MJK | last post by:
Suppose I have the following function in my program: void ExtractData(Ind *AM) { int i,j; char str; char c; FILE *ext=fopen("test.out","r"); //suppose I have N line each with M digits (in...
5
by: samifiaz | last post by:
I have to writen application in C# that can read or write data from a serial port. Can you please send any code that can help me for that. Or even material that can help me understanding this. ...
14
by: ravimishra11 | last post by:
Hi friends, I have written code in asp.net to read or write string in com port(COM1).But when i run the program i am not getting any output .Below is my code .How can i check the string which i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.