BplusDotNet.BplusTree.StringToBytes C# (CSharp) Method

StringToBytes() public static method

public static StringToBytes ( string thestring ) : byte[]
thestring string
return byte[]
        public static byte[] StringToBytes(string thestring)
        {
            System.Text.Encoder encode = System.Text.Encoding.UTF8.GetEncoder();
            char[] chars = thestring.ToCharArray();
            long length = encode.GetByteCount(chars, 0, chars.Length, true);
            byte[] bytes = new byte[length];
            encode.GetBytes(chars, 0, chars.Length,bytes, 0, true);
            return bytes;
        }

Usage Example

Example #1
0
        public override string PrefixForByteCount(string s, int maxbytecount)
        {
            byte[] inputbytes = BplusTree.StringToBytes(s);
            MD5    d          = MD5.Create();

            byte[] digest      = d.ComputeHash(inputbytes);
            var    resultbytes = new byte[maxbytecount];

            // copy digest translating to printable ascii
            for (int i = 0; i < maxbytecount; i++)
            {
                int r = digest[i % digest.Length];
                if (r > 127)
                {
                    r = 256 - r;
                }
                if (r < 0)
                {
                    r = -r;
                }
                //Console.WriteLine(" before "+i+" "+r);
                r = r % 79 + 40;               // printable ascii
                //Console.WriteLine(" "+i+" "+r);
                resultbytes[i] = (byte)r;
            }
            string result = BplusTree.BytesToString(resultbytes);

            return(result);
        }
All Usage Examples Of BplusDotNet.BplusTree::StringToBytes