<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../../style.css">
<title>
Gambas Documentation - Compress.String
 (gb.compress)</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../../../help+en"><img class="flag" alt="Home" border="0" src="../../../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../compress+en">Up</a>&nbsp;
<a href="open+en">Previous</a>&nbsp;
<a href="type+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Compress.String
 (gb.compress)</h1>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><font color="blue">FUNCTION</font> <b>String</b> <font color="blue">(</font> <u>Source</u> <font color="blue">AS</font> <font color="#0080FF">String</font> <b>[</b> <font color="blue">,</font> <u>Level</u> <font color="blue">AS</font> <font color="#0080FF">Integer</font><font color="blue">,</font> <u>AllowGrow</u> <font color="blue">AS</font> <font color="#0080FF">Boolean</font> <b>]</b> <font color="blue">)</font> <font color="blue">AS</font> <font color="#0080FF">String</font></pre>
This function returns a string compressed using the algorithm defined by the <a href="type+en">Type</a> property.
<p>
<ul>
<li><u>Source</u>: string to be compressed.
<li><u>Level</u>: compression level, a value from <a href="min+en">Min</a> value to <a href="max+en">Max</a> value. If this parameter is missing, Default will be used.
<li><u>AllowGrow</u>: If this parameter is missing, or you pass <a href="../../../lang/false+en">FALSE</a> as value, this function will return a compressed string only if its length is lesser than original (uncompressed) string length. If you pass <a href="../../../lang/true+en">TRUE</a>, it always will return the compressed string. Note that almost all compression algorithms can really compress a string  (reduce its length) only if it has clear patterns. Very short strings and random strings hardly can be compressed.
<p>
</ul>

<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">Dim Cz As New Compress
Dim Buf As String

Cz.Type = &quot;bzlib2&quot;

Buf = Cz.String(SourceString,Cz.Max,FALSE)

IF Len(Buf) &lt; Len(SourceString) THEN
    PRINT &quot;Compression successfully finished&quot;
ELSE
    PRINT &quot;Unable to compress that string&quot;
END IF</pre>

</div>
</body>
</html>

