PC Review


Reply
Thread Tools Rate Thread

cant concat more than 2 strings

 
 
Nikhil Patel
Guest
Posts: n/a
 
      21st Aug 2003
Hi,
I have following line in my code.

string strDDEExpression="[Replace(" + strWorkArea + ",";

When I run this and check the value in strDDEExpression, I find that the
comma is missing.

Any idea?

Thanks...

-Nikhil


 
Reply With Quote
 
 
 
 
David Browne
Guest
Posts: n/a
 
      21st Aug 2003

"Nikhil Patel" <(E-Mail Removed)> wrote in message
news:u$(E-Mail Removed)...
> Hi,
> I have following line in my code.
>
> string strDDEExpression="[Replace(" + strWorkArea + ",";
>
> When I run this and check the value in strDDEExpression, I find that the
> comma is missing.
>
> Any idea?


I think you have a trailing char(0) or null terminator in strWorkArea.

eg

char c = System.Text.Encoding.ASCII.GetChars( new byte[] {0})[0];
string strWorkArea = new string(new char[] {'h','e','l','l','o', c});
string strDDEExpression="[Replace(" + strWorkArea + ",";
Console.WriteLine(strDDEExpression);

outputs

[Replace(hello

You need to get rid of the null terminator.


David


 
Reply With Quote
 
Nikhil Patel
Guest
Posts: n/a
 
      21st Aug 2003
Ok.
now I get it. The string in C# works in C++ way. I am a VB programmer.
So forgot about null terminator. But I am wondering even in C++, when you
use "+" to concat strings, doesn't it get rid of the null terminators of all
strings except the last one?

Thanks David.

"David Browne" <davidbaxterbrowne no potted (E-Mail Removed)> wrote in
message news:#(E-Mail Removed)...
>
> "Nikhil Patel" <(E-Mail Removed)> wrote in message
> news:u$(E-Mail Removed)...
> > Hi,
> > I have following line in my code.
> >
> > string strDDEExpression="[Replace(" + strWorkArea + ",";
> >
> > When I run this and check the value in strDDEExpression, I find that the
> > comma is missing.
> >
> > Any idea?

>
> I think you have a trailing char(0) or null terminator in strWorkArea.
>
> eg
>
> char c = System.Text.Encoding.ASCII.GetChars( new byte[] {0})[0];
> string strWorkArea = new string(new char[] {'h','e','l','l','o', c});
> string strDDEExpression="[Replace(" + strWorkArea + ",";
> Console.WriteLine(strDDEExpression);
>
> outputs
>
> [Replace(hello
>
> You need to get rid of the null terminator.
>
>
> David
>
>



 
Reply With Quote
 
David Browne
Guest
Posts: n/a
 
      21st Aug 2003

"Nikhil Patel" <(E-Mail Removed)> wrote in message
news:O%(E-Mail Removed)...
> Ok.
> now I get it. The string in C# works in C++ way. I am a VB programmer.
> So forgot about null terminator. But I am wondering even in C++, when you
> use "+" to concat strings, doesn't it get rid of the null terminators of

all
> strings except the last one?
>


No a string in C# is exactly like a string in VB. Internally it is a fixed
length array of chars.
There is no need for a null terminator, since the array has a length.

string's in C# are NOT null termintated. You should never have a null char
in a string in C# or VB, and it's actually pretty hard to get one in there.

If you do manage to get a null char into a string, some things don't work
quite right.

It's just the only thing I could think of which would cause your
concatenation to fail.

David


 
Reply With Quote
 
Nikhil Patel
Guest
Posts: n/a
 
      21st Aug 2003
Hi,
I checked the value in strWorkArea. It is "86463496" and its length
property is 8. So I don't think there is any hidden character.

"David Browne" <davidbaxterbrowne no potted (E-Mail Removed)> wrote in
message news:#(E-Mail Removed)...
>
> "Nikhil Patel" <(E-Mail Removed)> wrote in message
> news:u$(E-Mail Removed)...
> > Hi,
> > I have following line in my code.
> >
> > string strDDEExpression="[Replace(" + strWorkArea + ",";
> >
> > When I run this and check the value in strDDEExpression, I find that the
> > comma is missing.
> >
> > Any idea?

>
> I think you have a trailing char(0) or null terminator in strWorkArea.
>
> eg
>
> char c = System.Text.Encoding.ASCII.GetChars( new byte[] {0})[0];
> string strWorkArea = new string(new char[] {'h','e','l','l','o', c});
> string strDDEExpression="[Replace(" + strWorkArea + ",";
> Console.WriteLine(strDDEExpression);
>
> outputs
>
> [Replace(hello
>
> You need to get rid of the null terminator.
>
>
> David
>
>



 
Reply With Quote
 
Michael Giagnocavo [MVP]
Guest
Posts: n/a
 
      21st Aug 2003
Can you create a small repro case? Could you send your compiled or
dissassembled (ILDASM) code too? What version of the framework are
you using?
-mike
MVP

"Nikhil Patel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I checked the value in strWorkArea. It is "86463496" and its

length
> property is 8. So I don't think there is any hidden character.
>
> "David Browne" <davidbaxterbrowne no potted (E-Mail Removed)> wrote

in
> message news:#(E-Mail Removed)...
> >
> > "Nikhil Patel" <(E-Mail Removed)> wrote in message
> > news:u$(E-Mail Removed)...
> > > Hi,
> > > I have following line in my code.
> > >
> > > string strDDEExpression="[Replace(" + strWorkArea + ",";
> > >
> > > When I run this and check the value in strDDEExpression, I find

that the
> > > comma is missing.
> > >
> > > Any idea?

> >
> > I think you have a trailing char(0) or null terminator in

strWorkArea.
> >
> > eg
> >
> > char c = System.Text.Encoding.ASCII.GetChars( new byte[] {0})[0];
> > string strWorkArea = new string(new char[] {'h','e','l','l','o',

c});
> > string strDDEExpression="[Replace(" + strWorkArea + ",";
> > Console.WriteLine(strDDEExpression);
> >
> > outputs
> >
> > [Replace(hello
> >
> > You need to get rid of the null terminator.
> >
> >
> > David
> >
> >

>
>



 
Reply With Quote
 
Nikhil Patel
Guest
Posts: n/a
 
      21st Aug 2003
Thanks all.

This is what I did and it works.
string strDDEExpression="[Replace(" +
strWorkArea.Remove(strWorkArea.Length-1,1) + ",";

"Nikhil Patel" <(E-Mail Removed)> wrote in message
news:u$(E-Mail Removed)...
> Hi,
> I have following line in my code.
>
> string strDDEExpression="[Replace(" + strWorkArea + ",";
>
> When I run this and check the value in strDDEExpression, I find that the
> comma is missing.
>
> Any idea?
>
> Thanks...
>
> -Nikhil
>
>



 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      21st Aug 2003
David,
> string's in C# are NOT null termintated. You should never have a null

char
> in a string in C# or VB, and it's actually pretty hard to get one in

there.
You do need null char in C#, VB6, & VB.NET strings when you are calling
Win32 APIs. As some Win32 APIs use a single null char as a seperator and
double null chars as a terminator.

Also, some external communication (TCP/IP, comm ports) may need null chars
in the middle of the string being transmitted...

It is actually rather nice that .NET Strings fully support null chars, as a
null char is still a valid character. Its just some of the interop stuff
chokes (debugger, System.Console, System.Diagnostics.Debug,
System.Diagnostics.Trace) when displayed in VS.NET especially.

Just a thought
Jay

"David Browne" <davidbaxterbrowne no potted (E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
>
> "Nikhil Patel" <(E-Mail Removed)> wrote in message
> news:O%(E-Mail Removed)...
> > Ok.
> > now I get it. The string in C# works in C++ way. I am a VB

programmer.
> > So forgot about null terminator. But I am wondering even in C++, when

you
> > use "+" to concat strings, doesn't it get rid of the null terminators of

> all
> > strings except the last one?
> >

>
> No a string in C# is exactly like a string in VB. Internally it is a

fixed
> length array of chars.
> There is no need for a null terminator, since the array has a length.
>
> string's in C# are NOT null termintated. You should never have a null

char
> in a string in C# or VB, and it's actually pretty hard to get one in

there.
>
> If you do manage to get a null char into a string, some things don't work
> quite right.
>
> It's just the only thing I could think of which would cause your
> concatenation to fail.
>
> David
>
>



 
Reply With Quote
 
Nikhil Patel
Guest
Posts: n/a
 
      21st Aug 2003
Do you mean I would not have gotton this problem if I were using v1.1?

"David Browne" <davidbaxterbrowne no potted (E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
>
> "Michael Giagnocavo [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > What version of the framework and compiler are you using? You can
> > have null chars in a string in .NET. The example code worked fine
> > (I'm using V1.1RC3).
> >
> > Thanks,
> > -mike
> > MVP

>
> The repro sample was for 1.0.
> The same code worked as correctly in 1.1.
>
> David
>
>



 
Reply With Quote
 
David Browne
Guest
Posts: n/a
 
      21st Aug 2003

"Nikhil Patel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Do you mean I would not have gotton this problem if I were using v1.1?
>


Yes, this appears to have been a bug in 1.0.

David


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it simply that c# converts all strings coming in to double and strings going out to single? AAaron123 Microsoft C# .NET 3 23rd Feb 2009 01:08 PM
Strings won't concat? =?Utf-8?B?S1ND?= Microsoft VB .NET 4 1st Aug 2005 06:17 PM
Make Word displays strings of text, not strings of code =?Utf-8?B?WGVybw==?= Microsoft Word Document Management 2 9th Dec 2004 10:35 AM
concat strings on sum query =?Utf-8?B?TWlrZQ==?= Microsoft Access Queries 3 6th Nov 2004 08:16 AM
can't concat more than 2 strings Nikhil Patel Microsoft C# .NET 8 22nd Aug 2003 12:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:04 PM.