解释代码
嗨,任何人都可以解释这些代码行,我需要了解它是如何工作的才能继续我正在做的事情
if (e.Error == null){
Stream responseStream = e.Result;
StreamReader responseReader = new StreamReader(responseStream);
string response = responseReader.ReadToEnd();
string[] split1 = Regex.Split(response, "},{");
List<string> pri1 = new List<string>(split1);
pri1.RemoveAt(0);
string last = pri1[pri1.Count() - 1];
pri1.Remove(last);
}
Hi can anyone explain these lines of codes, I need to understand how it works in order to proceed with what I am doing
if (e.Error == null){
Stream responseStream = e.Result;
StreamReader responseReader = new StreamReader(responseStream);
string response = responseReader.ReadToEnd();
string[] split1 = Regex.Split(response, "},{");
List<string> pri1 = new List<string>(split1);
pri1.RemoveAt(0);
string last = pri1[pri1.Count() - 1];
pri1.Remove(last);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果唯一要做的就是删除第一个和最后一个元素,我会使用
LinkedList
而不是List
。I would use a
LinkedList
instead ofList
if the only thing to do was to remove the first and last elements.它将响应流作为字符串读取,假设该字符串由用逗号分隔的序列“{...}”组成,例如:
{X},{Y},{Z},
然后将字符串拆分为“}, 数组
{",给出一个{X
Y
Z}
,然后从数组的第一个元素中删除第一个大括号 ( {X => X ),并从数组的最后一个元素中删除结束大括号 ( Z} => Z )。
It's reading the response stream as a string, making the assumption that the string consists of sequences "{...}" separated by commas, e.g.:
{X},{Y},{Z}
then splits the string on "},{", giving an array of
{X
Y
Z}
then removes the first brace from the first element of the array ( {X => X ) and the end brace from the last element of the array ( Z} => Z).
据我所知,它正在读取可能来自 TCP 的流。
它读取整个数据块,然后使用分隔符
},{
分隔数据块。因此,如果您有类似
abc},{dec
的内容,它将被放入包含 2 个值的 split1 数组中, split1 [0]=abc 、 split1 [1]=dec 。之后,它基本上删除了第一个和最后一个内容
From what I can see, it is reading from a stream that could have came from TCP.
It reads the whole chunk of data, then separate the chunk using the delimiter
},{
.So if you have something like
abc},{dec
, it will be placed into split1 array with 2 values, split1 [0]=abc , split1 [1]=dec.After that, it basically remove the 1st and the last content
它正在处理错误输出。
它从 e 接收到一个流(我猜这是一个例外),读取它。
它看起来像:
""{DDD},{我失败了},{因为},{没有信号}{ENDCODE}
它将它分成不同的字符串,并删除第一个和最后一个条目(DDD,ENDCODE)
It is processing an error output.
It received a stream from the e (I guess it is an exception), reads it.
It looks something like :
""{DDD},{I failed},{Because},{There was no signal}{ENDCODE}
It splits it into different string, and removes to fist and last entries (DDD, ENDCODE)