Article View: borland.public.csharpbuilder.language.csharp
Article #659UnicodeEncoding problem with marking.
From: Simon
Date: Fri, 17 Sep 2004 07:51
Date: Fri, 17 Sep 2004 07:51
78 lines
2935 bytes
2935 bytes
Hi,
I've just started using C# Builder (Personal) in an XP Home environment and
am having problems with generating marked Unicode files. When I pass a
"true" value as the second parameter to UnicodeEncoding I don't get a mark
added to the beginning of the file. Here's the example code I use,
using System;
using System.IO;
using System.Text;
namespace WriteFile
{
/// <summary>
/// Summary description for Class.
/// </summary>
class Class
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
string [] path = {@"c:\UnicodeLEM.txt",
@"c:\UnicodeLE.txt",
@"c:\UnicodeBEM.txt",
@"c:\UnicodeBE.txt"};
for (int i=0 ; i<4 ; i++)
{
if (File.Exists(path[i]))
File.Delete(path[i]);
using (FileStream f = File.Create(path[i]))
{
AddText(i,f,"This is a test");
}
}
}
private static void AddText(int i,FileStream fs, string value)
{
byte[] info = null;
switch (i)
{
case 0: info = new
UnicodeEncoding(false,true).GetBytes(value);
break;
case 1: info = new
UnicodeEncoding(false,false).GetBytes(value);
break;
case 2: info = new
UnicodeEncoding(true,true).GetBytes(value);
break;
case 3: info = new
UnicodeEncoding(true,false).GetBytes(value);
break;
}
fs.Write(info, 0, info.Length);
}
}
}
In all cases the "info.Length" is 28 bytes, I'd expect them to be 30 bytes f
or marked items.
Anyone have an idea what's going wrong.
Cheers
Simon
Technical Details
Message-ID:
<414a97dd@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,b413e5b5f8a488a4,start X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Simon" <simon@somba.com> Newsgroups: borland.public.csharpbuilder.language.csharp Subject: UnicodeEncoding problem with marking. Date: Fri, 17 Sep 2004 08:51:12 +0100 Lines: 80 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 NNTP-Posting-Host: 82.43.114.55 Message-ID: <414a97dd@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1095407581 82.43.114.55 (17 Sep 2004 00:53:01 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail