473,657 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extended ASCII Characters - StreamWriter

I am using StreamWriter's .Writeline() method to create a simple text file. I
found that ASCII characters 255 & 254 are being inserted as the first two
characters of the file which causes a 3rd-party users' parser to fail. It is
not being inserted by my data as the first line starts with "LOGIN: ", i.e.
hard-coded.

Has anyone else encountered this? Is there any filtering settings I can
apply? I looked through the documentation on
Nov 16 '05 #1
4 7702
Has anyone else encountered this? Is there any filtering settings I can
apply? I looked through the documentation on


The first two bytes are probably the little-endian Unicode byte order
marker. Who creates the StreamWriter, and which encoding is it using?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
Not sure what you mean by who creates StreamWriter - it's provided in the C#
language. I am using the default "UTF8Encodi ng".
"Mattias Sjögren" wrote:
Has anyone else encountered this? Is there any filtering settings I can
apply? I looked through the documentation on


The first two bytes are probably the little-endian Unicode byte order
marker. Who creates the StreamWriter, and which encoding is it using?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 16 '05 #3
Depending on how you create an instance of UTF8Encoding, you will get
different results. The encoding can contain a preamble, which identifies
the encoding used together with the encoded data. The
System.Encoding .UTF8 encoding always includes a preamble.

Using the code below you will get the output:

Stream length: 14
Stream length: 17
Stream length: 17

Which indicates that the first stream does not contain any preamble, but
the other two does.

Regards,
Joakim

using System;
using System.Text;
using System.IO;

public class App
{
public static void Main()
{
// Create an encoding without the preamble
MemoryStream ms1 = new MemoryStream();
StreamWriter w1 = new StreamWriter(ms 1, new UTF8Encoding(fa lse));
w1.Write("This is a test");
w1.Flush();
Console.WriteLi ne("Stream length: " + ms1.Length);

// Create an encoding specifically with the preamble
MemoryStream ms2 = new MemoryStream();
StreamWriter w2 = new StreamWriter(ms 2, new UTF8Encoding(tr ue));
w2.Write("This is a test");
w2.Flush();
Console.WriteLi ne("Stream length: " + ms2.Length);

// Use the default UTF8 encoding, which uses the preamble
MemoryStream ms3 = new MemoryStream();
StreamWriter w3 = new StreamWriter(ms 3, Encoding.UTF8);
w3.Write("This is a test");
w3.Flush();
Console.WriteLi ne("Stream length: " + ms3.Length);
}
}

ASP Yaboh wrote:
Not sure what you mean by who creates StreamWriter - it's provided in the C#
language. I am using the default "UTF8Encodi ng".

Nov 16 '05 #4
Joakim,

Thank you - I will check into this.

"Joakim Karlsson" wrote:
Depending on how you create an instance of UTF8Encoding, you will get
different results. The encoding can contain a preamble, which identifies
the encoding used together with the encoded data. The
System.Encoding .UTF8 encoding always includes a preamble.

Using the code below you will get the output:

Stream length: 14
Stream length: 17
Stream length: 17

Which indicates that the first stream does not contain any preamble, but
the other two does.

Regards,
Joakim

using System;
using System.Text;
using System.IO;

public class App
{
public static void Main()
{
// Create an encoding without the preamble
MemoryStream ms1 = new MemoryStream();
StreamWriter w1 = new StreamWriter(ms 1, new UTF8Encoding(fa lse));
w1.Write("This is a test");
w1.Flush();
Console.WriteLi ne("Stream length: " + ms1.Length);

// Create an encoding specifically with the preamble
MemoryStream ms2 = new MemoryStream();
StreamWriter w2 = new StreamWriter(ms 2, new UTF8Encoding(tr ue));
w2.Write("This is a test");
w2.Flush();
Console.WriteLi ne("Stream length: " + ms2.Length);

// Use the default UTF8 encoding, which uses the preamble
MemoryStream ms3 = new MemoryStream();
StreamWriter w3 = new StreamWriter(ms 3, Encoding.UTF8);
w3.Write("This is a test");
w3.Flush();
Console.WriteLi ne("Stream length: " + ms3.Length);
}
}

ASP Yaboh wrote:
Not sure what you mean by who creates StreamWriter - it's provided in the C#
language. I am using the default "UTF8Encodi ng".

Nov 16 '05 #5

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

Similar topics

1
3775
by: | last post by:
Hey all, Quick question...been bugging me for some time, really. I have a console app, it does some things, and I want to save an array of text to a text file. The text consists of ASCII and extended ascii (codes 0 to 255). I am using ofstream to output, and this is the line doing the actual output: outfile << screenbuffer.Char.AsciiChar; Note that screenbuffer is an array of type 'CHAR_INFO', quick info of it here: ...
13
7762
by: bgbauer70 | last post by:
My appologies if this ends up being a duplicate post. For some reason the first post never showed up. I've tried about 300 iterrations of this same ability, and none of them seem to work in Firefox. Take the following code for example. It WILL stop me from entering zero into the first text box, but it wont stop me from entering extended ascii characters (which is the final goal).
4
3841
by: wob | last post by:
Many thanks for those who responded to my question of "putting greek char into C string". In searching for an solution, I noticed that there are more than one version of "Extended ASCII characters"(No. 128 to 255) . e.g., in one version No. 224 is the symbol alpha, in another, it's a "a" with a ` on it... How come? You can see it here: http://www.kturby.com/cables/ascii2.htm
3
24500
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 ascii characters (eg "x" which is ascii character 120 gets translated to ascii character 130 which...
4
7226
by: =?Utf-8?B?Um9zaGFuIFIuRA==?= | last post by:
Hi All, I am new to C# programming; I am developing an application for recording audio data using voice modem. I am using HyperTerminal to manually process audio data. The modem when configured in voice record mode sends the audio (PCM) data on the serial port, few of the characters from these are in Extended ASCII range i.e. more than 127 decimal. In HyperTerminal we can reset the property to force the incoming data to 7 bit ASCII,...
1
2672
by: s123 | last post by:
Hi, while invoking a web service, if in xml request message i wrap the extended ASCII characters with CDATA it is not returning the desired result, while this is not the case if i do not wrap them with CDATA. I can not ignore the use of CDATA as for characters "<" and "&" i need to use it. I am not getting why it is not recognizing the Extended ASCII characters correctly when they are wrapped with CDATA, the problem is there only with DB2...
13
48065
by: ramif | last post by:
Is there a way to print extended ASCII in C?? I tried to code something, but it only displays strange symbols. here is my code: main() { char chr = 177; //stores the extended ASCII of a symbol printf("Character with an ascii code of 177: %c \n", chr); //tries to print an ASCII symbol...
0
3412
by: jumperbl | last post by:
I am converting hex to ASCII and one of the words has a dot in the middle, which is in the extended ascii characters. when i do this i get the ascii chars. binascii.unhexlify(''.join(value4.split())) Is there a way to print the extended characters as well. I currently get garbage where the dot is.
5
4658
by: siddhanta | last post by:
hi, i read the ascii value from a file and wrote the decimal one in other file. But values above "127" i.e. extended ascii are printed as" 65533." here ais wat i did: private void button1_Click(object sender, EventArgs e) { int b = new int; StreamReader sw = new StreamReader("c: \\28D.09N"); for (int i = 0; i < 5000; i++) {
0
8385
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8303
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8502
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8602
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7316
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4150
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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

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.