Re: String Bug or somethig I missunderstood?

Miguel Ángel Chacón <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.general
Message-ID <000401c21232$318798b0$1b40a8c0@gandalf>
Ok, but of which language are we talking about? I´m a VB/Java/C++/C#
programmer and my question is about how the string(C#) should be
terminated, I thought the zero was the mark, but now I don´t understand
anything. 

What is , then, the implementation of the string(C#)?

Some 


-----Mensaje original-----
De: The DOTNET list will be retired 7/1/02
[mailto:[email protected]] En nombre de Curtis Koppang
Enviado el: miércoles, 12 de junio de 2002 18:39
Para: [email protected]
Asunto: Re: [DOTNET] String Bug or somethig I missunderstood?

Are you a C programmer? ;-)  A char-zero is not used as the null
terminator
in a string.  Most string implementations (besides C) use some sort of
length descriptor to determine the length of the string.  To reinforce
this
point, check out the constructor for string - one takes an array of
chars.
If you were a Java or VB programmer this would seem perfectly normal to
you.

Later,
curt

----- Original Message -----
From: "Miguel Ángel Chacón" <[email protected]>
To: <[email protected]>
Sent: Wednesday, June 12, 2002 11:42 AM
Subject: [DOTNET] String Bug or somethig I missunderstood?


Just execute this lines of code and see the results. If you build a
string from a char array like this:
{'B','U','G',0,0,0,0}, the resulting string have a length of 8, and if
you build a new string adding some words to the first string and you
write it you´ll see 'blanks' for the '0' char, like this:
"BUG     NEW BUG". My expected result is that the length of the first
string to be 3 (no?) and when I add something the result should be
"BUGNEWBUG". Am I wrong?

using System;
using System.IO;

namespace StringBugTest
{
        class Class1
        {
                [STAThread]
                static void Main(string[] args)
                {
                        byte[] bytes = new byte[8];
                        bytes.SetValue((byte)66,0);
                        bytes.SetValue((byte)85,1);
                        bytes.SetValue((byte)71,2);
                        bytes.SetValue((byte)0,3);
                        bytes.SetValue((byte)0,4);
                        bytes.SetValue((byte)0,5);
                        bytes.SetValue((byte)0,6);
                        bytes.SetValue((byte)0,7);
                        MemoryStream ms=new MemoryStream(bytes);
                        BinaryReader bReader=new BinaryReader(ms);
                        char[] cadena=bReader.ReadChars(8);
                        string bug=new string(cadena);
                        Console.WriteLine(bug);
                        int a=bug.Length;
                        Console.WriteLine(a);
                        bug+="NEW BUG";
                        Console.WriteLine(bug);
                }
        }
}

Thanks for your attention.
Miguel Ángel Chacón Espín.
Telecinco. Spain.

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.