Sending a string containing special characters through a TcpClient (byte[])

后端 未结 3 1016
轻奢々
轻奢々 2021-01-05 01:54

I\'m trying to send a string containing special characters through a TcpClient (byte[]). Here\'s an example:

  • Client enters \"amé\" in a textbox
  • Client
3条回答
  •  鱼传尺愫
    2021-01-05 02:47

    Your question and your error is not clear to me but using Base64String may solve the problem
    Something like this

    static public string EncodeTo64(string toEncode)
        {
          byte[] toEncodeAsBytes
                = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
          string returnValue
                = System.Convert.ToBase64String(toEncodeAsBytes);
          return returnValue;
        }
    
    static public string DecodeFrom64(string encodedData)
        {
          byte[] encodedDataAsBytes
              = System.Convert.FromBase64String(encodedData);
          string returnValue =
             System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
          return returnValue;
        }
    

提交回复
热议问题