CHR(0) - breaking change in CF 3.5?

  • Thread starter Benjamin Lukner
  • Start date
B

Benjamin Lukner

Hi!

Dim NULL1 As Char = Chr(0)

I use a phrase like this ever since to generate a char that contains
ASCII character 0x00.

When running with CF 3.5, the variable is set to Nothing instead!

Can anybody confirm this behaviour? Bug or feature?

Regards,

Benjamin Lukner
 
S

Sid

Hi!

Dim NULL1 As Char = Chr(0)

I use a phrase like this ever since to generate a char that contains
ASCII character 0x00.

When running with CF 3.5, the variable is set to Nothing instead!

Can anybody confirm this behaviour? Bug or feature?

Hi there! Does not seem to be a "feature"... how can it be? A
character is a character, not Nothing...
In fact creating a Char with Chr(0) does set it to Nothing. And
Msgboxing Nothing gives an empty dialog.

Also watching the variable show it to be Nothing.

So I confirm the behavior, but don't know why this happen... Let us
informed!
 
B

Benjamin Lukner

Hi!

It's not about the CHR(0) itself. This is regular behaviour.
A message box always stops displaying at the first 0 character because
this indicates the end of the string.

That the DevEnv displays "Nothing" may be a feature or simply a bug.
Nevertheless it still is character 0.

The problem I experience is about the String.Replace() method.
I'll post another topic for this.

Kind regards,

Benjamin Lukner
 
C

Christopher Fairbairn [MVP]

Hi,

Benjamin Lukner said:
The problem I experience is about the String.Replace() method.
I'll post another topic for this.

If your string contains an embedded NULL character (which according to the
System.String documentation is a completely valid situation) .NET CF 3.5 may
not behave in the same way as previous releases.

Take a look at the following forum thread for example ".NET CF 3.5 Bug -
StringBuilder.Replace truncates result if data contains null character" -
available at
http://social.msdn.microsoft.com/Fo...t/thread/b5e008f0-40f8-4f9b-bcdb-9423411800b8

Is this the situation you are finding yourself in? It would help if you
could share a small code snippet demonstrating the issue you are finding.

Hope this helps,
Christopher Fairbairn
 
B

Benjamin Lukner

Is this the situation you are finding yourself in? It would help if you
could share a small code snippet demonstrating the issue you are finding.


Hi,

yes, that's the situation I experience.
I posted two messages but the second message (new topic) did not appear
here, though it's in my sent items folder. Here is a copy of that message:

Hi!

I experience a problem regarding the String.Replace() method when
running a .Net CF application with CF3.5:

When the second parameter is a string of CHR(0) the output string will
be truncated. This only occurs with CF3.5!

Running CF1.0 program with CF1.0 runtime: OK
Running CF1.0 program with CF2.0 runtime: OK
Running CF1.0 program with CF3.5 runtime: FAIL

Running CF2.0 program with CF2.0 runtime: OK
Running CF2.0 program with CF3.5 runtime: FAIL

Running CF3.5 program with CF3.5 runtime: FAIL


SAMPLE CODE:

Dim c0 As Char = Chr(0)
Dim s0 As String = New String(Chr(0), 1)

Dim s As String = "123X" + Chr(0) + "456"

' Expected: "123XX456"
MsgBox(s.Replace("X"c, c0).Replace(c0, "X"c)) '1A
MsgBox(s.Replace("X", c0).Replace(c0, "X")) '1B
MsgBox(s.Replace("X", s0).Replace(s0, "X")) '1C

' Expected: 8
MsgBox(s.Replace("X"c, c0).Length.ToString) '2A
MsgBox(s.Replace("X", c0).Length.ToString) '2B
MsgBox(s.Replace("X", s0).Length.ToString) '2C

' Expected: "X"
MsgBox(s0.Replace(c0, "X"c)) '3A
MsgBox(s0.Replace(c0, "X")) '3B
MsgBox(s0.Replace(s0, "X")) '3C


CONCLUSION:

When replacing any char with char 0 there's no problem at all.
But when replacing with a String of char 0 the output string will be
truncated: 1B, 1C, 2B, 2C will fail with CF3.5 but work with all other
runtime versions.

Kind regards,

Benjamin Lukner
 
C

Christopher Fairbairn [MVP]

Hi Benjamin,

Benjamin Lukner said:
I experience a problem regarding the String.Replace() method when running
a .Net CF application with CF3.5:

When the second parameter is a string of CHR(0) the output string will be
truncated. This only occurs with CF3.5!

This has been identified as a bug in the .NET CF 3.5 runtime.

As the Microsoft developers in the MSDN forum thread I referenced suggested
you may like to take a look at Microsoft's bug tracking system
(http://connect.microsoft.com/) and check if it has already been posted
there. If it has then you could post a validation saying the issue is
affecting you, alternatively if it hasn't you could create a new case.

If you have a copy of Visual Studio with MSDN you may also be able to use a
Service Request with Microsoft Technical Support to get feedback directly
from Microsoft (see details on how this option works at
http://blogs.msdn.com/raffael/archive/2008/05/14/get-what-you-paid-for.aspx)

Hope this helps,
Christopher Fairbairn
 
B

Benjamin Lukner

Christopher Fairbairn [MVP] wrote:
[...]
As the Microsoft developers in the MSDN forum thread I referenced suggested
you may like to take a look at Microsoft's bug tracking system
(http://connect.microsoft.com/) and check if it has already been posted
there. If it has then you could post a validation saying the issue is
affecting you, alternatively if it hasn't you could create a new case.

Thanks for the information, I just posted the issue. But the sign up
procedure is rather complicated I think and takes much effort. There are
only a few steps but several confirmation mails and typing codes et
cetera. In fact it seems like Microsoft tries to keep away users from
the service...

Kind regards

BL
 
B

Benjamin Lukner

Christopher Fairbairn [MVP] wrote:
[...]
As the Microsoft developers in the MSDN forum thread I referenced suggested
you may like to take a look at Microsoft's bug tracking system
(http://connect.microsoft.com/) and check if it has already been posted
there. If it has then you could post a validation saying the issue is
affecting you, alternatively if it hasn't you could create a new case.

Thanks for the information, I just posted the issue. But the sign up
procedure is rather complicated I think and takes much effort. There are
only a few steps but several confirmation mails and typing codes et
cetera. In fact it seems like Microsoft tries to keep away users from
the service...

Kind regards

BL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top