Search code examples
c#socketstcpclient

How to identify STX character in a string


I am using TCPClient in my code, and I can find start and end of the text in a string successfully.

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

But I have another string which contains STX at the beginning of the string. How can I identify STX in c#?


Solution

  • STX is just a Unicode character

    const char STX = '\u0002';
    

    And you can work with it like with any other character:

    String source = ...
        
    bool starts = source.StartsWith(STX.ToString()); 
    bool contains = source.Contains(STX);