System.Text.Encoding.GetCharCount C# (CSharp) Method

GetCharCount() public method

public GetCharCount ( byte bytes ) : int
bytes byte
return int
        public virtual int GetCharCount(byte[] bytes)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException("bytes",
                    Environment.GetResourceString("ArgumentNull_Array"));
            }
            return GetCharCount(bytes, 0, bytes.Length);
        }

Same methods

Encoding::GetCharCount ( byte bytes, int count ) : int
Encoding::GetCharCount ( byte bytes, int count, DecoderNLS decoder ) : int
Encoding::GetCharCount ( byte bytes, int index, int count ) : int

Usage Example

示例#1
0
        /// <summary>
        /// Applies the clang-format replacements (xml) to the current view
        /// </summary>
        private static void ApplyClangFormatReplacements(string replacements, IWpfTextView view)
        {
            // clang-format returns no replacements if input text is empty
            if (replacements.Length == 0)
            {
                return;
            }

            var root              = XElement.Parse(replacements);
            var edit              = view.TextBuffer.CreateEdit();
            int last_offset_utf8  = 0;
            int last_offset_utf16 = 0;

            foreach (XElement replacement in root.Descendants("replacement"))
            {
                int offset_utf8 = int.Parse(replacement.Attribute("offset").Value);
                int length_utf8 = int.Parse(replacement.Attribute("length").Value);
                // convert the multi bytes index to utf16 index
                // assume that offsets is in order.
                int offset_utf16 = enc.GetCharCount(buffer, last_offset_utf8, offset_utf8 - last_offset_utf8) + last_offset_utf16;
                int length_utf16 = enc.GetCharCount(buffer, offset_utf8, length_utf8);
                edit.Replace(offset_utf16, length_utf16, replacement.Value);
                last_offset_utf8  = offset_utf8;
                last_offset_utf16 = offset_utf16;
            }
            edit.Apply();
            view.Selection.Clear();
        }
All Usage Examples Of System.Text.Encoding::GetCharCount