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


C# UTF8Encoding.GetByteCount方法代码示例

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


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

示例1: PosTest1

 public void PosTest1()
 {
     String chars = "UTF8 Encoding Example";
     UTF8Encoding utf8 = new UTF8Encoding();
     int byteCount = utf8.GetByteCount(chars);
     Assert.Equal(chars.Length, byteCount);
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:UTF8EncodingGetByteCount2.cs

示例2: PosTest2

 public void PosTest2()
 {
     String chars = "";
     UTF8Encoding utf8 = new UTF8Encoding();
     int byteCount = utf8.GetByteCount(chars);
     Assert.Equal(0, byteCount);
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:UTF8EncodingGetByteCount2.cs

示例3: sendString

 public void sendString(String st) { 
     UTF8Encoding asen = new UTF8Encoding();
     lock (lock1){
         s.Send(BitConverter.GetBytes(asen.GetByteCount(st)),4,SocketFlags.None); 
         s.Send(asen.GetBytes(st));
     }
 }
开发者ID:TheBugMaker,项目名称:Payload-Client,代码行数:7,代码来源:Writer.cs

示例4: getByteCount

 public static int getByteCount(string value)
 {
     int count = 0;
     UTF8Encoding utf8 = new UTF8Encoding();
     count = utf8.GetByteCount(value);
     return count + 4;
 }
开发者ID:adoggie,项目名称:TCE,代码行数:7,代码来源:serialize.cs

示例5: PosTest2

 public void PosTest2()
 {
     Char[] chars = new Char[] { };
     UTF8Encoding utf8 = new UTF8Encoding();
     int byteCount = utf8.GetByteCount(chars, 0, 0);
     Assert.Equal(0, byteCount);
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:UTF8EncodingGetByteCount1.cs

示例6: TestSizeWithUKPound

 public void TestSizeWithUKPound()
 {
     UTF8Encoding encoding = new UTF8Encoding();
     int baseSize = 5;
     String test = "1£";
     BsonString bstr = new BsonString(test);
     Assert.AreEqual(baseSize + encoding.GetByteCount(test), bstr.Size, "Size didn't count the double wide pound symbol correctly");
 }
开发者ID:jesseemerick,项目名称:mongodb-csharp,代码行数:8,代码来源:TestBsonString.cs

示例7: ToUTF8Bytes

        public static byte[] ToUTF8Bytes(this string cultureStringMsg)
        {
            UTF8Encoding encoding = new UTF8Encoding();
            int dataLen = encoding.GetByteCount(cultureStringMsg);
            byte[] utf8bytes = new byte[dataLen];
            Encoding.UTF8.GetBytes(cultureStringMsg, 0, cultureStringMsg.Length, utf8bytes, 0);

            return utf8bytes;
        }
开发者ID:alphaCoder,项目名称:DotNetCode,代码行数:9,代码来源:Extensions.cs

示例8: NegTest1

 public void NegTest1()
 {
     String chars = null;
     UTF8Encoding utf8 = new UTF8Encoding();
     Assert.Throws<ArgumentNullException>(() =>
     {
         int byteCount = utf8.GetByteCount(chars);
     });
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:9,代码来源:UTF8EncodingGetByteCount2.cs

示例9: Init_ServerCommunication

        public static SslStream Init_ServerCommunication(string URL, int Port)
        {
            UTF8Encoding encoder = new UTF8Encoding();

            //
            //First create the header
            //
            byte ver = 2;
            byte opcode = 0;
            ushort response = 0;
            string uri = @"h";
            string data = "Hiya: \"hi\"";

            byte[] header = new byte[8];
            header[0] = ver;
            header[1] = opcode;
            header[2] = BitConverter.GetBytes(response)[0];
            header[3] = BitConverter.GetBytes(response)[1];

            if (encoder.GetByteCount(uri) > ushort.MaxValue)
                throw new Exception("The URI is too large to send");
            ushort uriLength = (ushort)encoder.GetByteCount(uri);

            if (encoder.GetByteCount(data) > ushort.MaxValue)
                throw new Exception("The data is too large to send");
            ushort dataLength = (ushort)encoder.GetByteCount(data);

            header[4] = BitConverter.GetBytes(uriLength)[0];
            header[5] = BitConverter.GetBytes(uriLength)[1];
            header[6] = BitConverter.GetBytes(dataLength)[0];
            header[7] = BitConverter.GetBytes(dataLength)[1];

            TcpClient clientSocket = new TcpClient(URL, Port);

            SslStream sslStream = new SslStream(clientSocket.GetStream(), false, new RemoteCertificateValidationCallback(CertificateValidationCallback));

            sslStream.AuthenticateAsClient(URL);

            sslStream.Write(header, 0, 8);
            sslStream.Write(encoder.GetBytes(uri), 0, uriLength);
            sslStream.Write(encoder.GetBytes(data), 0, dataLength);

            return sslStream;
        }
开发者ID:tcd-tophat,项目名称:networking-test-wp7,代码行数:44,代码来源:Program.cs

示例10: PosTest1

 public void PosTest1()
 {
     Char[] chars = new Char[] {
                     '\u0023',
                     '\u0025',
                     '\u03a0',
                     '\u03a3'  };
     UTF8Encoding utf8 = new UTF8Encoding();
     int byteCount = utf8.GetByteCount(chars, 1, 2);
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:UTF8EncodingGetByteCount1.cs

示例11: ConvertUTF8ToBytes

		protected string ConvertUTF8ToBytes(string str) 
		{
			UTF8Encoding utf8 = new UTF8Encoding();

			int byteCount = utf8.GetByteCount(str);
			Byte[] bytes = new Byte[byteCount];
			utf8.GetBytes(str, 0, str.Length, bytes, 0);

			return Convert.ToBase64String(bytes);
		}
开发者ID:nguyenhuuhuy,项目名称:mygeneration,代码行数:10,代码来源:CollectionSerializer.cs

示例12: PosTest2

        public void PosTest2()
        {
            Byte[] bytes;
            Char[] chars = new Char[] { };

            UTF8Encoding utf8 = new UTF8Encoding();

            int byteCount = utf8.GetByteCount(chars, 0, 0);
            bytes = new Byte[byteCount];
            int charsEncodedCount = utf8.GetChars(bytes, 0, 0, chars, 0);
            Assert.Equal(0, charsEncodedCount);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:12,代码来源:UTF8EncodingGetChars.cs

示例13: NegTest3

 public void NegTest3()
 {
     Char[] chars = new Char[] {
                     '\u0023',
                     '\u0025',
                     '\u03a0',
                     '\u03a3'  };
     UTF8Encoding utf8 = new UTF8Encoding();
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         int byteCount = utf8.GetByteCount(chars, 1, -2);
     });
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:13,代码来源:UTF8EncodingGetByteCount1.cs

示例14: IsReaderName

        /// <summary>
        /// �����û���
        /// </summary>
        /// <param name="str">��֤���ַ���</param>
        /// <returns></returns>
        public static bool IsReaderName(string str)
        {
            UTF8Encoding encoding = new UTF8Encoding();
            int byteCount = encoding.GetByteCount(str);
            int strLen = str.Length;

            if (strLen == byteCount)
            {
                return true;
            }

            return false;
        }
开发者ID:zhouyige,项目名称:aspwork,代码行数:18,代码来源:CommonRG.cs

示例15: IsSBC

        /// <summary>
        /// 全角验证
        /// </summary>
        /// <param name="str">验证的字符串</param>
        /// <returns></returns>
        public static bool IsSBC(string str)
        {
            UTF8Encoding encoding = new UTF8Encoding();
            int byteCount = encoding.GetByteCount(str);
            int strLen = str.Length;

            if (byteCount == strLen * 3)
            {
                return true;
            }

            return false;
        }
开发者ID:conghuiw,项目名称:exam-report,代码行数:18,代码来源:Validation.cs


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