当前位置: 首页>>代码示例>>C#>>正文


C# ASCIIEncoding.GetString方法代码示例

本文整理汇总了C#中System.Text.ASCIIEncoding.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# ASCIIEncoding.GetString方法的具体用法?C# ASCIIEncoding.GetString怎么用?C# ASCIIEncoding.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.ASCIIEncoding的用法示例。


在下文中一共展示了ASCIIEncoding.GetString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: connect

 //Connect to the client
 public void connect()
 {
     if (!clientConnected)
     {
         IPAddress ipAddress = IPAddress.Any;
         TcpListener listener = new TcpListener(ipAddress, portSend);
         listener.Start();
         Console.WriteLine("Server is running");
         Console.WriteLine("Listening on port " + portSend);
         Console.WriteLine("Waiting for connections...");
         while (!clientConnected)
         {
             s = listener.AcceptSocket();
             s.SendBufferSize = 256000;
             Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
             byte[] b = new byte[65535];
             int k = s.Receive(b);
             ASCIIEncoding enc = new ASCIIEncoding();
             Console.WriteLine("Received:" + enc.GetString(b, 0, k) + "..");
             //Ensure the client is who we want
             if (enc.GetString(b, 0, k) == "hello" || enc.GetString(b, 0, k) == "hellorcomplete")
             {
                 clientConnected = true;
                 Console.WriteLine(enc.GetString(b, 0, k));
             }
         }
     }
 }
开发者ID:kartikeyadubey,项目名称:share,代码行数:29,代码来源:Server.cs

示例2: Search

        public object Search(queryrequest xml)
        {
            SemWeb.Query.Query query = null;

            string q = string.Empty;

            try
            {
                query = new SparqlEngine(new StringReader(xml.query));
            }
            catch (QueryFormatException ex)
            {
                var malformed = new malformedquery();

                malformed.faultdetails = ex.Message;

                return malformed;
            }

            // Load the data from sql server
            SemWeb.Stores.SQLStore store;

            string connstr = ConfigurationManager.ConnectionStrings["SemWebDB"].ConnectionString;

            DebugLogging.Log(connstr);

            store = (SemWeb.Stores.SQLStore)SemWeb.Store.CreateForInput(connstr);

            //Create a Sink for the results to be writen once the query is run.
            MemoryStream ms = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(ms, System.Text.Encoding.UTF8);
            QueryResultSink sink = new SparqlXmlQuerySink(writer);

            try
            {
                // Run the query.
                query.Run(store, sink);

            }
            catch (Exception ex)
            {
                // Run the query.
                query.Run(store, sink);
                DebugLogging.Log("Run the query a second time");
                DebugLogging.Log(ex.Message);

            }
            //flush the writer then  load the memory stream
            writer.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            //Write the memory stream out to the response.
            ASCIIEncoding ascii = new ASCIIEncoding();
            DebugLogging.Log(ascii.GetString(ms.ToArray()).Replace("???", ""));
            writer.Close();

            DebugLogging.Log("End of Processing");

            return SerializeXML.DeserializeObject(ascii.GetString(ms.ToArray()).Replace("???", ""), typeof(sparql)) as sparql;
        }
开发者ID:shariqatariq,项目名称:profiles-rns,代码行数:60,代码来源:ProfilesSPARQLAPI.svc.cs

示例3: SetupForCtcp

 /// <summary>
 /// Wrap a message as a CTCP command
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="ctcpCommand">
 /// The CTCP command.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public static string SetupForCtcp(this string message, string ctcpCommand)
 {
     var asc = new ASCIIEncoding();
     byte[] ctcp = { Convert.ToByte(1) };
     return asc.GetString(ctcp) + ctcpCommand.ToUpper()
            + (message == string.Empty ? string.Empty : " " + message) + asc.GetString(ctcp);
 }
开发者ID:tom29739,项目名称:helpmebot,代码行数:19,代码来源:CtcpExtensions.cs

示例4: TRK

        public TRK(Stream Data)
        {
            m_Reader = new FileReader(Data, false);
            string DataStr = "";
            string[] Elements;

            ASCIIEncoding Enc = new ASCIIEncoding();
            string MagicNumber = Enc.GetString(m_Reader.ReadBytes(4));

            if (!MagicNumber.Equals("2DKT", StringComparison.InvariantCultureIgnoreCase) && !MagicNumber.Equals("TKDT", StringComparison.InvariantCultureIgnoreCase))
                throw new HitException("Invalid TrackData header - TRK.cs");

            if (MagicNumber.Equals("2DKT", StringComparison.InvariantCultureIgnoreCase))
            {
                DataStr = Enc.GetString(m_Reader.ReadBytes((int)m_Reader.ReadUInt32()));
                Elements = DataStr.Split(',');
            }
            else
                Elements = Enc.GetString(m_Reader.ReadToEnd()).Split(',');

            m_Version = int.Parse(Elements[1], NumberStyles.Integer);
            TrackName = Elements[2];

            if (!Elements[3].Equals("", StringComparison.InvariantCultureIgnoreCase))
                SoundID = uint.Parse(Elements[3].Replace("0x", ""), NumberStyles.HexNumber);
            else
                SoundID = 0;

            if (Elements[5].Equals("\r\n", StringComparison.InvariantCultureIgnoreCase))
                return;

            if (!Elements[5].Equals("", StringComparison.InvariantCultureIgnoreCase))
                Argument = (HITTrackArguments)Enum.Parse(typeof(HITTrackArguments), Elements[5]);

            if (!Elements[7].Equals("", StringComparison.InvariantCultureIgnoreCase))
                ControlGroup = (HITControlGroup)Enum.Parse(typeof(HITControlGroup), Elements[7]);

            if (!Elements[(m_Version != 2) ? 11 : 12].Equals("", StringComparison.InvariantCultureIgnoreCase))
                DuckingPriority = int.Parse(Elements[(m_Version != 2) ? 11 : 12], NumberStyles.Integer);

            if (!Elements[(m_Version != 2) ? 12 : 13].Equals("", StringComparison.InvariantCultureIgnoreCase))
                Looped = (int.Parse(Elements[(m_Version != 2) ? 12 : 13], NumberStyles.Integer) != 0) ? true : false;

            if (!Elements[(m_Version != 2) ? 13 : 14].Equals("", StringComparison.InvariantCultureIgnoreCase))
                Volume = int.Parse(Elements[(m_Version != 2) ? 13 : 14], NumberStyles.Integer);

            m_Reader.Close();
        }
开发者ID:Afr0Games,项目名称:Project-Dollhouse,代码行数:48,代码来源:TRK.cs

示例5: HandleClient

        private static void HandleClient(object client)
        {
            TcpClient tcpClient = (TcpClient)client;
            EndPoint remote = tcpClient.Client.RemoteEndPoint;

            NetworkStream clientStream = tcpClient.GetStream();
            int bytesRead;
            byte[] message = new byte[tcpClient.ReceiveBufferSize];

            ASCIIEncoding encoder = new ASCIIEncoding();

            while (true)
            {
                bytesRead = 0;
                string strMessage = "";
                try
                {
                    bytesRead = clientStream.Read(message, 0, tcpClient.ReceiveBufferSize);

                    strMessage = encoder.GetString(message, 0, bytesRead);
                    Console.WriteLine(String.Format("{1} just sent: {0}", strMessage, remote.ToString()));
                }
                catch
                {
                    //error = true;
                    break;
                }

                if (bytesRead == 0)
                    break;

            }
        }
开发者ID:krandor,项目名称:GameEngine,代码行数:33,代码来源:Program.cs

示例6: Serialize

        public static int Serialize(Kowhai.kowhai_node_t[] descriptor, byte[] data, out string target, Object getNameParam, GetSymbolName getName)
        {
            kowhai_get_symbol_name_t _getName = delegate(IntPtr param, UInt16 value)
            {
                return getName(getNameParam, value);
            };

            byte[] targetBuf;
            int targetBufferSize = 0x1000;
            int result;
            Kowhai.kowhai_tree_t tree;
            GCHandle h = GCHandle.Alloc(descriptor, GCHandleType.Pinned);
            tree.desc = h.AddrOfPinnedObject();
            GCHandle h2 = GCHandle.Alloc(data, GCHandleType.Pinned);
            tree.data = h2.AddrOfPinnedObject();
            do
            {
                targetBufferSize *= 2;
                targetBuf = new byte[targetBufferSize];
                result = kowhai_serialize(tree, targetBuf, ref targetBufferSize, IntPtr.Zero, _getName);
            }
            while (result == Kowhai.STATUS_TARGET_BUFFER_TOO_SMALL);
            h2.Free();
            h.Free();
            ASCIIEncoding enc = new ASCIIEncoding();
            target = enc.GetString(targetBuf, 0, targetBufferSize);
            return result;
        }
开发者ID:othane,项目名称:kowhai,代码行数:28,代码来源:KowhaiSerialize.cs

示例7: ByteArrayToString

 public string ByteArrayToString(Byte[] bArray)
 {
     string str;
     System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
     str = enc.GetString(bArray);
     return str;
 }
开发者ID:nadar71,项目名称:Krea,代码行数:7,代码来源:ComInterProcess.cs

示例8: Chr

 //ASCII 码转字符
 public static string Chr(int asciiCode)
 {
     System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
                     byte[] byteArray = new byte[] { (byte)asciiCode };
                     string strCharacter = asciiEncoding.GetString(byteArray);
                     return (strCharacter);
 }
开发者ID:Strongc,项目名称:sencond,代码行数:8,代码来源:ZkdBpSap.cs

示例9: BytesToUuid

        /// <summary>
        /// Returns the Uuid from a series of bytes
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public static string BytesToUuid(AppendableByteArray bytes, int offset)
        {
            byte[] uuid = bytes.GetSubarray(offset, UUID_LEN);

            ASCIIEncoding encoding = new ASCIIEncoding();
            return encoding.GetString(uuid);
        }
开发者ID:zwagoth,项目名称:whip-dotnet-client,代码行数:13,代码来源:Util.cs

示例10: GetCommand

 public string GetCommand()
 {
     System.Text.ASCIIEncoding enc = new ASCIIEncoding();
     byte[] buf = new byte[this.data.Length - 8];
     Array.Copy(this.data, 8, buf, 0, buf.Length);
     return enc.GetString(buf);
 }
开发者ID:Willyham,项目名称:SagaRO2,代码行数:7,代码来源:CPCommand.cs

示例11: HandleClientComm

        private void HandleClientComm(object client)
        {
            TcpClient tcpClient = (TcpClient)client;
            NetworkStream clientStream = tcpClient.GetStream ();

            byte[] message = new byte[4096];
            int bytesRead;

            while (true) {
                bytesRead = 0;

                try {
                    //blocks until a client sends a message
                    bytesRead = clientStream.Read (message, 0, 4096);
                }
                catch {
                    //a socket error has occured
                    break;
                }

                if (bytesRead == 0) {
                    //the client has disconnected from the server
                    break;
                }

                //message has successfully been received
                ASCIIEncoding encoder = new ASCIIEncoding ();
                Console.WriteLine (encoder.GetString (message, 0, bytesRead));
                byte[] buffer = encoder.GetBytes("01");
                clientStream.Write(buffer, 0 , buffer.Length);
                clientStream.Flush();
            }

            tcpClient.Close ();
        }
开发者ID:alberje,项目名称:asland-server,代码行数:35,代码来源:andserver.cs

示例12: DisplayMessageReceived

        void DisplayMessageReceived(byte[] message)
        {
            ASCIIEncoding encoder = new ASCIIEncoding();
            string str = encoder.GetString(message, 0, message.Length);

            tbReceived.Text += str + "\r\n";
        }
开发者ID:tmek,项目名称:PinballEventProtocol,代码行数:7,代码来源:Form1.cs

示例13: TC001_FileServerTest

        public void TC001_FileServerTest()
        {
            string user = Credentials.GenerateCredential();
            string password = Credentials.GenerateCredential();

            string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
            Directory.CreateDirectory(tempPath);

            File.WriteAllText(Path.Combine(tempPath, "test.txt"), "this is a test");

            int port = NetworkInterface.GrabEphemeralPort();

            FileServer fs = new FileServer(port, tempPath, "foobar", user, password);

            fs.Start();

            WebClient client = new WebClient();
            NetworkCredential credentials = new NetworkCredential(user, password);
            client.Credentials = credentials;
            byte[] data = client.DownloadData(String.Format("http://{0}:{1}/foobar/test.txt", "localhost", port));

            ASCIIEncoding encoding = new ASCIIEncoding();
            string retrievedContents = encoding.GetString(data);

            Assert.IsTrue(retrievedContents.Contains("this is a test"));

            //Thread.Sleep(6000000);

            fs.Stop();
        }
开发者ID:jayakumark,项目名称:vcap-dotnet,代码行数:30,代码来源:FileServerTest.cs

示例14: DoQuestion

        public static string DoQuestion(string txt)
        {
            TcpClient client = new TcpClient();

            IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000);

            try
            {
                client.Connect(serverEndPoint);

                NetworkStream clientStream = client.GetStream();

                ASCIIEncoding encoder = new ASCIIEncoding();
                byte[] buffer = encoder.GetBytes(txt);

                clientStream.ReadTimeout = 1000;
                clientStream.Write(buffer, 0, buffer.Length);
                clientStream.Flush();

                buffer = new Byte[128];
                int size = clientStream.Read(buffer, 0, buffer.Length);

                client.Close();
                return encoder.GetString(buffer, 0, buffer.Length);
            }
            catch
            {
                return "failed";
            }
        }
开发者ID:ds9999,项目名称:SuperKiGaV-EX,代码行数:30,代码来源:RightsMgmt.cs

示例15: Update

    // Update is called once per frame
    void Update()
    {
        if (server.Pending())
        {
            //print ("comunica com cliente");
            cliente = server.AcceptSocket();
            cliente.Blocking = false;

            // operacoes de escrita e leitura com cliente
            byte [] mensagem = new byte[1024];
            cliente.Receive (mensagem); //leitura da mensagem enviada pelo cliente
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding ();
            strMessage = encoding.GetString (mensagem).ToString (); // string contendo mensagem recebida do cliente
            //print (strMessage);

            //prepara mensagem para envio
            byte[] envioBuffer = new byte[4];
            envioBuffer[0] = (byte)'a';
            envioBuffer[1] = (byte)'c';
            envioBuffer[2] = (byte)'k';
            envioBuffer[3] = 10;
            cliente.Send(envioBuffer); //envia mensagem ao cliente

        }

        // utiliza a mensagem recebida do cliente que foi armazenada
        // na variavel strMessage para atuar no objeto Cube da cena
        if (strMessage.Contains("noventa")) {
            meuservo.GetComponent<Servo_Motor_Limitado>().rotacao = 90; // rotaciona o servo em 90 graus
        }
    }
开发者ID:ClaudioMota,项目名称:SimuladorRoboUnity,代码行数:32,代码来源:servidor.cs


注:本文中的System.Text.ASCIIEncoding.GetString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。