Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 24th, 2004, 11:21 AM
Authorized User
 
Join Date: Dec 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to skip/ignore null(\0) chars from stream?

Hi,

My C# application is getting data stream from remote server. After getting receiving the data from socket, i am converting it to "String" thru the ASCII encoder(Encoder.GetString()).

In the streamed data, there are some "null" characters which is indicated as '\0'. I do not know how these chars are coming with the stream. But, the streamed data is perfectly correct data and i have checked that. I am supposed to skip those null characters and read the subsequent characters.

The problem i am facing now is that the embedded '\0' characters are getting mixed with the "Date" fields and thus invalidating the "Date". How to resolve this? i.e. How to skip/ignore the embedded '\0' chars in the stream. Am i making any mistake with encoders... ASCII... UTF...or something else?

Hope you guys can help me resolve this.

Thanks in advance.

Regards,
Peri


 
Old December 27th, 2004, 05:04 PM
tnd tnd is offline
Authorized User
 
Join Date: Jun 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Since you are using string, did you check account for unicode characters?
If your string is "ABC", when converted into bytearray it's 0, 65, 0, 66, 0, 67. Remember unicode is 2-byte each.
Note: I arbitrarily used a machine encoding of MSB-LSB. I do not remember how windows encodes them, so the string may be 65, 0, 66, 0, 67, 0. You should determine this yourself.

Also you may find it easier to change datetime variable directly into 8 byte byte-arrary and by-pass the whole unicode/string conversion process if both your server and client are written with .NET

 
Old December 28th, 2004, 09:01 PM
Authorized User
 
Join Date: Dec 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, tnd.

The stream is ASCII and not Unicode. Got to know from another source that since network streams don't end and they are continuous, embedded nulls are normal. I do not understand the full meaning of this... but it seems presence of nulls in streams is normal.

I am currently stripping off those nulls after validating the stream for checksum.

Thanks and regards,
Peri







Similar Threads
Thread Thread Starter Forum Replies Last Post
skip first field gilgalbiblewheel Classic ASP Databases 1 July 7th, 2007 05:10 PM
Why would this skip record #1? dep XSLT 8 November 1st, 2006 02:57 PM
Skip a row rochak SQL Server DTS 2 September 27th, 2005 11:06 PM
Skip On Refresh Prabhakar_dt Classic ASP Basics 9 September 2nd, 2004 11:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.