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


C# Encoding.GetByteCount方法代码示例

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


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

示例1: WriteToStream

        public void WriteToStream(Stream outputStream, Encoding encoding)
        {
            outputStream.WriteByte((Byte)'P');

            // message length =
            // Int32 self
            // name of prepared statement + 1 null string terminator +
            // query string + 1 null string terminator
            // + Int16
            // + Int32 * number of parameters.
            Int32 messageLength = 4 + encoding.GetByteCount(_prepareName) + 1 + encoding.GetByteCount(_queryString) + 1 + 2 + (_parameterIDs.Length * 4);
            //Int32 messageLength = 4 + _prepareName.Length + 1 + _queryString.Length + 1 + 2 + (_parameterIDs.Length * 4);

            PGUtil.WriteInt32(outputStream, messageLength);
            PGUtil.WriteString(_prepareName, outputStream, encoding);
            PGUtil.WriteString(_queryString, outputStream, encoding);
            PGUtil.WriteInt16(outputStream, (Int16)_parameterIDs.Length);


            for(Int32 i = 0; i < _parameterIDs.Length; i++)
                PGUtil.WriteInt32(outputStream, _parameterIDs[i]);




        }
开发者ID:nlhepler,项目名称:mono,代码行数:26,代码来源:NpgsqlParse.cs

示例2: WriteToStream

        public void WriteToStream(Stream outputStream, Encoding encoding)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteToStream");

            switch (protocolVersion) {
            case ProtocolVersion.Version2 :
                // Write the size of the packet.
                // 4 + (passwordlength + 1) -> Int32 + NULL terminated string.
                // output_stream.Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(4 + (password.Length + 1))), 0, 4);
                PGUtil.WriteInt32(outputStream, 4 + encoding.GetByteCount(password) + 1);

                // Write String.
                PGUtil.WriteString(password, outputStream, encoding);

                break;

            case ProtocolVersion.Version3 :
                outputStream.WriteByte((Byte)'p');
                PGUtil.WriteInt32(outputStream, 4 + encoding.GetByteCount(password) + 1);

                // Write String.
                PGUtil.WriteString(password, outputStream, encoding);

                break;

            }
        }
开发者ID:nlhepler,项目名称:mono,代码行数:27,代码来源:NpgsqlPasswordPacket.cs

示例3: GetByteLength

 public override int GetByteLength(Encoding encoding)
 {
     int byteLength = 0;
     byteLength += encoding.GetByteCount(indicator);
     foreach (SubField sf in subfields)
     {
         byteLength += encoding.GetByteCount(Field.SubFieldStart.ToString());
         byteLength += sf.GetByteLength(encoding);
     }
     byteLength += encoding.GetByteCount(Field.FieldEnd.ToString());
     return byteLength;
 }
开发者ID:SJupiter,项目名称:CNMARC,代码行数:12,代码来源:DataField.cs

示例4:

 public static string PadRightInBytes
                     (
                         this string text
                         , int totalWidth
                         , char paddingChar = ' '
                         , Encoding encoding = null
                     )
 {
     if (encoding == null)
     {
         encoding = Encoding.GetEncoding("gb2312");
     }
     totalWidth -=
                     (
                         encoding.GetByteCount(text)
                         - text.Length
                     );
     return
         text
             .PadRight
                 (
                     totalWidth
                     , paddingChar
                 );
 }
开发者ID:Microshaoft,项目名称:Microshaoft.Common.Utilities.Net.4x,代码行数:25,代码来源:StringsHelper.cs

示例5: GetByteCount

        public unsafe static int GetByteCount(Encoding encoding, char[] chars, int index, int count)
        {
            // Validate parameters

            Contract.Assert(encoding != null); // this parameter should only be affected internally, so just do a debug check here
            if (chars == null)
            {
                throw new ArgumentNullException("chars", Environment.GetResourceString("ArgumentNull_Array"));
            }
            if (index < 0 || count < 0)
            {
                throw new ArgumentOutOfRangeException(index < 0 ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (chars.Length - index < count)
            {
                throw new ArgumentOutOfRangeException("chars", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
            }
            Contract.EndContractBlock();

            // If no input, return 0, avoid fixed empty array problem
            if (count == 0)
                return 0;

            // Just call the (internal) pointer version
            fixed (char* pChars = chars)
                return encoding.GetByteCount(pChars + index, count, encoder: null);
        }
开发者ID:Rayislandstyle,项目名称:dotnet-coreclr,代码行数:27,代码来源:EncodingForwarder.cs

示例6: StringStream

        public StringStream(string str, Encoding encoding = null)
        {
            _string = str ?? string.Empty;
            _encoding = encoding ?? Encoding.UTF8;

            _byteLength = _encoding.GetByteCount(_string);
        }
开发者ID:huseyint,项目名称:StringStream,代码行数:7,代码来源:StringStream.cs

示例7: WriteToStream

        public void WriteToStream( Stream outputStream, Encoding encoding )
        {
            //NpgsqlEventLog.LogMsg( this.ToString() + _commandText, LogLevel.Debug  );


            String commandText = _command.GetCommandText();
            
            // Tell to mediator what command is being sent.
            
            _command.Connector.Mediator.SqlSent = commandText;
            
            // Send the query to server.
            // Write the byte 'Q' to identify a query message.
            outputStream.WriteByte((Byte)'Q');

            if (_protocolVersion == ProtocolVersion.Version3)
            {
                // Write message length. Int32 + string length + null terminator.
                PGUtil.WriteInt32(outputStream, 4 + encoding.GetByteCount(commandText) + 1);
            }

            // Write the query. In this case it is the CommandText text.
            // It is a string terminated by a C NULL character.
            PGUtil.WriteString(commandText, outputStream, encoding);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:25,代码来源:NpgsqlQuery.cs

示例8: ReadStringInternalDynamic

        internal static string ReadStringInternalDynamic(this Stream stream, Encoding encoding, char end)
        {
            int characterSize = encoding.GetByteCount("e");
            Debug.Assert(characterSize == 1 || characterSize == 2 || characterSize == 4);
            string characterEnd = end.ToString();

            int i = 0;
            byte[] data = new byte[128 * characterSize];

            while (true)
            {
                if (i + characterSize > data.Length)
                {
                    Array.Resize(ref data, data.Length + (128 * characterSize));
                }

                int read = stream.Read(data, i, characterSize);
                Debug.Assert(read == characterSize);

                if (encoding.GetString(data, i, characterSize) == characterEnd)
                {
                    break;
                }

                i += characterSize;
            }

            if (i == 0)
            {
                return "";
            }

            return encoding.GetString(data, 0, i);
        }
开发者ID:nortex,项目名称:d3sharp,代码行数:34,代码来源:Internal.cs

示例9: MetaData

 public MetaData(Roles role, Actions action, ContentTypes contentType, Encoding encoding, string message)
 {
     this.role = role;
     this.action = action;
     this.contentType = contentType;
     this.encoding = encoding;
     messageSize = encoding.GetByteCount(message);
 }
开发者ID:PushkinTyt,项目名称:Chat,代码行数:8,代码来源:MetaData.cs

示例10: ReadStringData

        /// <summary>
        /// Reads the string data.
        /// </summary>
        /// <param name="binaryReader">The binary reader.</param>
        /// <param name="encoding">The encoding.</param>
        /// <returns></returns>
        public static string ReadStringData(this BinaryReader binaryReader, Encoding encoding)
        {
            int size = binaryReader.ReadUInt16();

            return encoding.GetString(
                binaryReader.ReadBytes(
                    size * encoding.GetByteCount(" ")));
        }
开发者ID:hrudham,项目名称:Quicken,代码行数:14,代码来源:BinaryReaderExtensions.cs

示例11: WriteNullTermString

        public static void WriteNullTermString(this Stream stream, string value, Encoding encoding)
        {
            var dataLength = encoding.GetByteCount(value);
            var data = new byte[dataLength + 1];
            encoding.GetBytes(value, 0, value.Length, data, 0);
            data[dataLength] = 0x00; // '\0'

            stream.Write(data, 0, data.Length);
        }
开发者ID:vhsoaresr,项目名称:Dota2,代码行数:9,代码来源:StreamHelpers.cs

示例12: TestEncoding

 private void TestEncoding(Encoding enc, int byteCount, int maxByteCount, byte[] bytes)
 {
     Assert.Equal(byteCount, enc.GetByteCount(s_myChars));
     Assert.Equal(maxByteCount, enc.GetMaxByteCount(s_myChars.Length));
     Assert.Equal(enc.GetBytes(s_myChars), bytes);
     Assert.Equal(enc.GetCharCount(bytes), s_myChars.Length);
     Assert.Equal(enc.GetChars(bytes), s_myChars);
     Assert.Equal(enc.GetString(bytes, 0, bytes.Length), s_myString);
     Assert.NotEqual(0, enc.GetHashCode());
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:ConvertUnicodeEncodings.cs

示例13: GetByteCount

        /// <summary>
        /// Gets the number of bytes for specified string in given encoding.
        /// </summary>
        /// <param name="encoding">The encoding.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static int GetByteCount(Encoding encoding, string value)
        {
            if (encoding == null) {
                throw new ArgumentNullException("encoding");
            }
            if (value == null) {
                throw new ArgumentNullException("value");
            }

            return encoding.GetByteCount(value);
        }
开发者ID:Titaye,项目名称:SLExtensions,代码行数:17,代码来源:ByteUtility.cs

示例14: Create

        public static unsafe IntPtr Create(string text, Encoding encoding)
        {
            // Avoid unnecessary allocations by allocating the native buffer directly in managed code
            var byteCount = encoding.GetByteCount(text);
            var bytesPointer = (byte*)Marshal.AllocHGlobal(byteCount);

            fixed (char* charsPointer = text)
                encoding.GetBytes(charsPointer, text.Length, bytesPointer, byteCount);

            return SafeNativeMethods.objc_msgSend(Class, Selectors.DataWithBytesNoCopyLengthFreeWhenDone, (IntPtr)bytesPointer, checked((IntPtr)byteCount), true);
        }
开发者ID:nagyist,项目名称:monoxide,代码行数:11,代码来源:Data.cs

示例15: StringToPtr

 	public static IntPtr StringToPtr(string value, Encoding encoding)
     {
         var encoder = encoding.GetEncoder();
         var length = encoding.GetByteCount(value);
         // The encoded value is null terminated that's the reason for the '+1'.
         var encodedValue = new byte[length + 1];
         encoding.GetBytes(value, 0, value.Length, encodedValue, 0);
         var handle = Marshal.AllocHGlobal(new IntPtr(encodedValue.Length));
         Marshal.Copy(encodedValue, 0, handle, encodedValue.Length);
         return handle;
     }
开发者ID:Picazsoo,项目名称:tesseract,代码行数:11,代码来源:MarshalHelper.cs


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