无法合并两个字符串! [英] can't merge two string!
问题描述
在我最新的C#应用程序中,它从串行通信设备将字节流读取到字节数组,在读取操作之后,我将其存储到字符串变量中
在存储它之前,我调用下面的函数将其转换为字符串
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
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
return enc.GetString(input);
但结果两个字符串无法合并
but the resulted two string can''t be merged
string resultString = string1 + string2;
我也检查了两种组合
I also check both combination
string resultString = string2 + string1;
那么只有string2内容存储在resultString
合并期间未发生异常,结果字符串始终在第一个字符串中显示内容
我认为结尾字符可能会引起问题吗?
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?
推荐答案
不确定您是如何合并"字符串的,但它应该像下面这样简单:
Not sure how you are "merging" the strings, but it should be as easy as:
string resultString = string1 + string2;
字符串不正确.在组合两个sring之前,请检查第二个字符串以确保正确.
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.
我认为我们可能缺少一些故事.试试这个看看你能得到什么:
I think we''re probably missing some of the story. Try this to see what you get:
string resultString = string1.Length.ToString() + ", " + string2.Length.ToString();
这篇关于无法合并两个字符串!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!