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

GetBytes() public method

public GetBytes ( String s ) : byte[]
s String
return byte[]
        public virtual byte[] GetBytes(String s)
        {
            if (s == null)
                throw new ArgumentNullException("s",
                    Environment.GetResourceString("ArgumentNull_String"));

            char[] chars = s.ToCharArray();
            return GetBytes(chars, 0, chars.Length);
        }

Same methods

Encoding::GetBytes ( char chars ) : byte[]
Encoding::GetBytes ( char chars, int index, int count ) : byte[]
Encoding::GetBytes ( String s, int charIndex, int charCount, byte bytes, int byteIndex ) : int
Encoding::GetBytes ( char chars, int charCount, byte bytes, int byteCount ) : int
Encoding::GetBytes ( char chars, int charCount, byte bytes, int byteCount, EncoderNLS encoder ) : int
Encoding::GetBytes ( char chars, int charIndex, int charCount, byte bytes, int byteIndex ) : int

Usage Example

        public static void ProcessCommand(string command, Stream io, int security, string user, Encoding encoding)
        {
            if (String.IsNullOrWhiteSpace(command))
            {
                return;
            }

            try
            {
                byte[] writebuffer;

                var cmdsplit = command.Split(' ');
                if (cmdsplit.Length < 1) return;
                var label = cmdsplit[0];

                if (SBWAPI.PluginManager.Default.ProcessCommand(label, command, io, security, user, encoding)) return;

                if (command.StartsWith("#"))
                {
                    if (security < 4)
                    {
                        writebuffer =
                            encoding.GetBytes(
                                "\u001B[31mYou do not have permission to send special commands\u001B[0m\r\n");
                        io.Write(writebuffer, 0, writebuffer.Length);
                        return;
                    }

                    if (CommandProcessors.ContainsKey(label))
                        CommandProcessors[label](command, io, security, user, encoding);
                    return;
                }
                if (command.StartsWith("/"))
                {
                    if (security < 3)
                    {
                        writebuffer = encoding.GetBytes(
                            "\u001B[31mYou do not have permission to send commands\u001B[0m\r\n");
                        io.Write(writebuffer, 0, writebuffer.Length);
                        return;
                    }

                    if (CommandProcessors.ContainsKey(label))
                        CommandProcessors[label](command, io, security, user, encoding);
                    else
                    {
                        ServerHandler.ProcessHandler.ExtOutput(string.Format("<{0}> {1}", user, command));
                        ServerHandler.ProcessHandler.Instance.Command(command.Remove(0, 1));
                    }
                    return;
                }

                CommandProcessors["\uFFFF"](command, io, security, user, encoding);
            }
            catch
            {
            }
        }
All Usage Examples Of System.Text.Encoding::GetBytes