Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
In my latest C# application which reads a byte stream from a serial communication device to a byte array, after the reading operation I store it into a string variable

before storing it I call the below function to convert it to string

C++
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
return enc.GetString(input);


but the resulted two string can't be merged

C#
string resultString = string1 + string2;


I also check both combination

C#
string resultString = string2 + string1;


then only string2 content stores in the resultString

no exception occurred during merging , the resulted string always shows the content in the first string

I think the ending character may cause the problem?
Posted
Updated 5-Mar-10 3:39am
v8

Not sure how you are "merging" the strings, but it should be as easy as:
C#
string resultString = string1 + string2;
 
Share this answer
 
In all likelihood, your second string isn't correct. Check your second string to make sure it is correct before you combine the two srings.
 
Share this answer
 
I think we're probably missing some of the story. Try this to see what you get:
C#
string resultString = string1.Length.ToString() + ", " + string2.Length.ToString();
 
Share this answer
 
there can be null error so please

try the following code


String Result=string1.toString()+string2.toString();
if (string1==null || string2==null) Console.WriteLine("You just got a NullReferenceException (Goe bezig!)");


It will concate your string.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900