如何识别字符串中的STX字符

时间:2016-06-22 10:53:40

标签: c# sockets tcpclient

我在我的代码中使用TCPClient,我可以在字符串中成功找到文本的开头和结尾。

e.g Start of Text : <Root> End of Text : </Root>

但我有另一个字符串,在字符串的开头包含STX。如何识别c#中的STX

1 个答案:

答案 0 :(得分:2)

STX只是一个ASCII字符

https://en.wikipedia.org/wiki/ASCII

  const char STX = '\u0002';

你可以像任何其他角色一样使用它:

  String source = ...

  bool starts = source.StartsWith(STX.ToString()); 
  bool contains = source.Contains(STX);
相关问题