Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hi all
i have one function which generates string
that string is very lengthy.
i want to decrease its length and size
 
this is my code and result:
not posting real string it is very long
protected void Page_Load(object sender, EventArgs e)
    {
        string txt = "somestring";
        Label1.Text = txt.Length.ToString();
        string cmpString = Compress(txt);
        Label2.Text = cmpString.Length.ToString();
    }
 
//For Compression
    public string Compress(string text)
            {
            byte[] buffer = Encoding.UTF8.GetBytes(text);
            MemoryStream ms = new MemoryStream();
            using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true))
            {
            zip.Write(buffer, 0, buffer.Length);
            }
            ms.Position = 0;
            byte[] compressed = new byte[ms.Length];
            ms.Read(compressed, 0, compressed.Length);
            byte[] gzBuffer = new byte[compressed.Length + 4];
            System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
            System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
            return Convert.ToBase64String(gzBuffer);
    
    }
 
result:
465832
667296
 

 
my question is when i m compressing the data the length of that string should reduce it is increasing
is there any solution becoz i want to minimize its length and size.
Posted 2-Aug-12 1:58am
MAU7871.6K
Edited 2-Aug-12 2:14am
_Amy51.3K
v3
Comments
Vani Kulkarni at 2-Aug-12 6:59am
   
What is the question?
MAU787 at 2-Aug-12 7:02am
   
my question is when i m compressing the data the length of that string should reduce it is increasing
is there any solution becoz i want to minimize its length and size
barneyman at 2-Aug-12 7:12am
   
are you forgetting that b64 encoding adds 33% ?
MAU787 at 2-Aug-12 7:14am
   
ohh really?
so what shud i do for reducing its size??

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
You are converting your string to byte and again displaying it in string format?
The string representation of byte will be big in length and size anyway. Store it in byte only.
 

--Amit
  Permalink  
Comments
MAU787 at 2-Aug-12 7:17am
   
thanx for reply
 
do you have reference code for it??
_Amy at 2-Aug-12 7:22am
   
You should try Google[^].
MAU787 at 2-Aug-12 7:26am
   
thanx
but i wanted to pass string only...i want to reduce length of that string while passing.
barneyman at 2-Aug-12 8:17am
   
your requirements are less than explicit - but, maybe you want to look at passing by reference?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Maciej Los 305
2 Richard MacCutchan 270
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,834
1 Sergey Alexandrovich Kryukov 7,477
2 DamithSL 5,689
3 Maciej Los 5,329
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 2 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100