WriteLine problem with " character

nl2ttl

Member
Joined
Nov 9, 2006
Messages
16
Programming Experience
Beginner
I;mn working on a program that create a little .bat file with some commands in it.

Only i need to use this kind of text: "TEST APP"

oWrite.WriteLine(" "TEST APP" ")

Write line dosn't understand the "TEST APP" because the " character is part of the syntax. Is there a way to use the " character in combination with the writeline command
 
ControlChars.Quote

There are a bunch of control chars for this exact situation (Line Breaks, Different Types of Quotes, Etc.) Also, if you are feeling sassy you can use

VB.NET:
Dim intCharCode as integer
'set intcharcode to the character you want
intCharCode = 34
Chr(intCharCode)

However controlchars.quote should do it for you.
 
Thank you for your replay this is working.
Only now i need to create a .bks file that will be saved in unicode format

(simpel notepad editing .bks files won't work)

So does somebody know how to create a .bks file with notepad
 
Notice the use of two double-quote chars in the string:
VB.NET:
oWrite.WriteLine(" ""TEST APP"" ")
What is oWrite? a StreamWriter? If so it defaults to UTF8 without Byte-Order-Mark, if you need to set BOM you must use the constructor where you specify UTF8 encoding. Not sure what you are meaning about Notepad, according to HOW TO: Manually Edit Ntbackup.exe Selection Script Files Notepad can be used, so the .bks file is definitive plain text.
 
Yeah you're right its StreamWriter. When i create a document with the streamwriter its not unicode text type.

So the .bks file created with StreamWriter won't work. Is there a way to do it?
 
I'm now using:

Dim sw As New IO.StreamWriter("G:\Backup\Backup_TEST.bks", False, System.Text.Encoding.UTF8)

But i need it in UTF16 format with the BOM (byte order mark) off.

Somebody know how to do it?
 
The How-To says to save as Unicode when using Notepad, this is a Utf16 file with preamble on.
VB.NET:
Dim sw As New IO.StreamWriter("G:\Backup\Backup_TEST.bks", False, System.Text.Encoding.Unicode)
 
Oke the file is nu a unicode (UTF-16) format. Only the BOM is still checked when I open the file with SuperEdit.

When I create a .bks file with ntbackup the BOM is unchecked, the unchecked one works the checked one not.

Aaargh :mad:
 
Then the MS how-to is wrong, which is far from the first time, but it sounds strange that you can't in that case use Notepad (* different versions?) to edit such a script. To prevent preamble you can use an Encoding to convert strings to bytes and write these to an open IO.FileStream.
VB.NET:
Dim enc As System.Text.Encoding = System.Text.Encoding.Unicode
Dim fs As New IO.FileStream("noPreamble.txt", IO.FileMode.Create, IO.FileAccess.Write)
Dim bytes() As Byte = enc.GetBytes("utf16 encoded text, no preamble in file" & vbNewLine)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
 
Back
Top