[Mono-list] C# Hexadecimal Escape Char Anomalies???

Matthew Franz mdfranz@io.com
Mon, 23 Feb 2004 09:37:56 -0600


Thanks for all the helpful responses. They helped me realize that Strings
aren't the way to go, because I needed use byte anyway since that is
ultimately what I needed for sending out on the network with.
SendTo
  
byte[] b = {0x00, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF};

- mdf

>         
> Well, you are forgetting that C# strings are Unicode (UTF-16 encoded)
> and when output to any stream it will be converted to that stream's
> encoding. In the case of the console the output encoding is governed by
> the LANG environment variable. See:
>         
> [rafael@redhat9]$ export LANG=en_US
> [rafael@redhat9]$ mono bobo.exe | od -h
> 0000000 ffff
> 0000002
> [rafael@redhat9]$ export LANG=en_US.UTF-8
> [rafael@redhat9]$ mono bobo.exe | od -h
> 0000000 bfc3 bfc3
> 0000004
> 
> where the source is:
> 
> [rafael@redhat9]$ cat bobo.cs
> using System;
>  
> class SimpleTest
> {
>         public static void Main (String[]args)
>         {
>                 String bobo = "\xFF\xFF";
>                 System.Console.Write (bobo);
>         }
> }
> 
> Note: When outputting to a stream you are creating, you can choose what
> encoding the stream will use, so you have better control of the
> situation than with the console.
> 
> Hope it helps,
> -- 
> Rafael "Monoman" Teixeira 
> Mono Hacker since 16 Jul 2001 - http://www.go-mono.org/
> Mono Brasil Founding Member - http://monobrasil.redesolbrasil.org/
> English Blog: http://monoblog.blogspot.com/
> Brazilian Portuguese Blog: http://monoblog.weblogger.terra.com.br/
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list

-- 
| Matthew Franz                              mdfranz@io.com |
|              http://www.io.com/~mdfranz                   |