Byte [] Buffer = New Byte [Client. receivebuffersize];
This . Isactive = True ;
While (Client. getstream (). Read (buffer, 0 , Buffer. length) ! = 0 )
{
String data = System. Text. encoding. Default. getstring (buffer );
Int I = 0 ; // 0 is valid, 1 is a character after 1B, and 2 is invalid
String data2 = "" ;
Converting a buffer directly to a string will surprise you.
[2; 37; 0 m
This is the ANSI color.Code,
The ASCII values of "[" are hexadecimal 1B, hexadecimal 27, hexadecimal 5B, and hexadecimal 91, respectively.
The original idea was to traverse each character and filter out ANSI
// Foreach (char C in data. tochararray ())
// {
// If (C = (char) 27) // 1bh 27o''
// {
// I = 1;
// Continue;
// }
// If (I = 1 & C = (char) 91) // 5bh 91o''
// {
// I = 2;
// Continue;
// }
// If (I = 2)
// If (C ==( char) 109) // 36 h running o 'M'
// {
// I = 0;
// Continue;
// }
// Else
// Continue;
// Data2 = data2 + C;
// }
However, the efficiency is too low, so the thought of RegEx. Replace ()
Data2 = RegEx. Replace (data, @ "\ [\ D] {} (; [\ D] {}) {} m ","");
It is not general.
I have to study trigger recently. It should be easy to use RegEx, but zmud does not use the standard RegEx and should be well written.AlgorithmConversion
Just so