. NET string gzip compression and Base64string conversions:

Source: Internet
Author: User

 classProgram {Static voidMain (string[] args) {            //the string to compress            stringdata ="13800138000, Verification code: 1234 "Huaxin" \r\n13800138000, Captcha: 4567 "Huaxin""; byte[] buffer =System.Text.UTF8Encoding.UTF8.GetBytes (data); //the compressed byte array            byte[] Compressedbuffer =NULL; //Compress buffer, compressed cacheMemoryStream ms =NewMemoryStream (); using(GZipStream ZS =NewGZipStream (MS, Compressionmode.compress,true) ) {Zs. Write (Buffer,0, buffer.                Length); //The following two commented out code is problematic, the corresponding Compressedbuffer length only 10--the 10 bytes should only compress the header of buffer//ZS.                Flush (); //Compressedbuffer = Ms.           ToArray ();             }            //only GZipStream should respond to Memorystream.toarray () after dispose of the buffer is the result we needCompressedbuffer =Ms.            ToArray (); //basse64 string After compressing a byte array            stringText64 =convert.tobase64string (Compressedbuffer);            Console.WriteLine (Text64);        Console.readkey (); }    }

. NET string gzip compression and Base64string conversions:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.