System.Text.UTF8Encoding.GetBytes C# (CSharp) Method

GetBytes() private method

private GetBytes ( char chars, int charCount, byte bytes, int byteCount ) : int
chars char
charCount int
bytes byte
byteCount int
return int
        public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
        {
            throw null;
        }

Same methods

UTF8Encoding::GetBytes ( char chars, int charIndex, int charCount, byte bytes, int byteIndex ) : int
UTF8Encoding::GetBytes ( string s, int charIndex, int charCount, byte bytes, int byteIndex ) : int

Usage Example

        protected string Encode(string value)
        {
            UTF8Encoding encoding = new UTF8Encoding();

            switch (_DataType.Encoding)
            {
                case "BASE64": return Convert.ToBase64String(encoding.GetBytes(value));
                case "7BIT":
                case "8BIT":                
                    value = Regex.Replace(value, @"[^\r]\n", "\r\n");
                    value = Regex.Replace(value, @"\r[^\n]", "\r\n");

                    bool is7Bit = _DataType.Encoding.Equals("7BIT");

                    List<byte> data = new List<byte>(encoding.GetBytes(value));
                    for (int i = data.Count - 1; i >= 0; i--)
                    {
                        if (data[i] == 0)
                            data.RemoveAt(i);

                        if (is7Bit && data[i] > 127)
                            data.RemoveAt(i);
                    }

                    return encoding.GetString(data.ToArray());
                default:
                    return value;
            }
        }
All Usage Examples Of System.Text.UTF8Encoding::GetBytes