lundi 27 juin 2016

How to remove mentioned characters from network stream string

I am doing telnet from a web page using TcpClient

server = new TcpClient(ConfigurationManager.AppSettings["DynamicIP"], Convert.ToInt32(ConfigurationManager.AppSettings["DynamicPort"]));
            ns = server.GetStream();

While reading response of a stream with below method.

if (ns.CanRead)
        {
            byte[] readBuffer = new byte[1024];
            int numBytesRead = 0;
            do
            {
                numBytesRead = ns.Read(readBuffer, 0, readBuffer.Length);
                // ss= Encoding.GetEncoding(1252).GetString(readBuffer.ToArray());
                //sb.Append(readBuffer[0].ToString);
                sb.AppendFormat("{0}", Encoding.ASCII.GetString(readBuffer, 0, numBytesRead));
                sb.Replace(Convert.ToChar(24), ' ');
                sb.Replace(Convert.ToChar(255), ' ');
                sb.Replace('?', ' ');
                //sb.Replace(Environment.NewLine, "<br />").ToString();
            }
            while (ns.DataAvailable);
        }
        // var s = Regex.Replace(sb.ToString(), @"[^u0000-u007F]", string.Empty);
        //var s = "<br/>" + sb.ToString();
        //s = s.Normalize(NormalizationForm.FormD);
        //var chars = s.Where(c => CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark).ToArray();
        //return new string(chars).Normalize(NormalizationForm.FormC);
        ////return "<br/>" + s.ToString();
        var dd = "<br/>" + sb.ToString();
        return dd;

but string contains the below characters in it. How to remove or replace in order to show the telnet response in readable format in web form? I have tried so many things, but in vain.

I would like to show the response in webpage just like Putty reads the response.

Thanks in advance.

;40f;9f;40f;9f;40f;2f;40f;9f[4;34f;9f[4;37f;2f[4;34f;9f[4;34f;11f;40f;9f;40f;9f;40f;11f[4;39f;9f[4;34f;11f[4;37f;9f[4;34f;9f[4;37f;40f[4;34f;40f;9f;40f;11f;40f;11f;40f;9f[4;37f;9f[4;37f;9f[4;37f;11f[4;34f;9f[4;34f;40f[4;34f;40f;11f;40f;11f;40f;11f;40f;9f[4;39f;2f[4;34f;9f[4;37f;9f[4;34f;40f[4;37f;40f;9f;40f;9f;40f;9f;40f;11f[4;37f;9f[4;37f;11f[4;37f;9f[4;34f;40f[4;37f;40f[4;37f;40f;9f;40f;2f;40f;9f[4;37f;9f[4;37f;11f[4;37f;11f[4;39f;9f[4;37f;40f;9f;40f;9f;40f;11f;40f;9f;40f;9f[4;34f;2f[4;34f;9f[4;37f;11f[4;34f;40f[4;37f;40f[4;34f;40f"

Aucun commentaire:

Enregistrer un commentaire