Perl Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Perl Examples

Quick Start
Unicode
Byte Array
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
Signatures
SMTP
Socket / SSL
Spider
SFTP
SSH Key
SSH
SSH Tunnel
Tar
HTTP Upload
XML
XMP
Zip

More Examples...
String
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

The Chilkat StringArray object

The Chilkat string array object is a utility class used by many of the Chilkat components. It's not an array. It's an object that contains 0 or more strings that can be retrieved by index. The reason Chilkat created this object is that string arrays are handled differently in different programming languages. The CkStringArray object (or Chilkat.StringArray in .NET) is used whenever a collection of strings is passed to a method, or returned from a method. This example demonstrates some very basic usage. How to create a string array, populate it with some entries, sort it, retrieve entries, etc.

 Chilkat Perl Module Downloads for Windows, Linux, and MAC OS X

use chilkat();

#  This is not an array -- it's an object.
$sa = new chilkat::CkStringArray();

#  Append some strings.
$sa->Append("abc");
$sa->Append("Abc");
$sa->Append("123");
$sa->Append("Chilkat Software, Inc.");

#  How many strings?

$n = $sa->get_Count();
print $n . "\r\n";

#  Iterate over the strings contained in the object:

for ($i = 0; $i <= $n - 1; $i++) {
    print $sa->getString($i) . "\r\n";
}

#  Sort in ascending order:

$ascending = 1;
$sa->Sort($ascending);

print "Sorted:" . "\r\n";
for ($i = 0; $i <= $n - 1; $i++) {
    print $sa->getString($i) . "\r\n";
}

#  Save to a file (one string per line).
#  Line endings are controlled by the Crlf property.
$useCrlf = 1;
$sa->put_Crlf($useCrlf);
$sa->SaveToFile("strings.txt");

#  Clear the string array.
$sa->Clear();

#  Load the string array from a file.  Each line in the
#  file becomes a string contained in the object:
$sa->LoadFromFile("strings.txt");

#  Remove a string by exact match:
$sa->Remove("abc");

#  Remove a string by index (1st string is at index 0):
$sa->RemoveAt(2);

#  The Trim property can be set to automatically trim whitespace
#  from the beginning and end of any string added to the object:
$sa->put_Trim(1);

#  Append some strings from a comma-separated list:
$sa->SplitAndAppend("apple, orange, banana, pear, lime",",");

#  What do we have now?
print "-------- After SplitAndAppend:" . "\r\n";
$n = $sa->get_Count();
for ($i = 0; $i <= $n - 1; $i++) {
    print $sa->getString($i) . "\r\n";
}

#  Serialize the complete object to a base64 string:

$serialized = $sa->serialize();

print "-------- Serialized:" . "\r\n";
print $serialized . "\r\n";

#  Restore from a serialized string:
$sa2 = new chilkat::CkStringArray();
$sa2->AppendSerialized($serialized);

print "-------- After AppendSerialized:" . "\r\n";
$n = $sa2->get_Count();
for ($i = 0; $i <= $n - 1; $i++) {
    print $sa2->getString($i) . "\r\n";
}

#  Set the Unique property to prevent duplicates from being added:
$sa->put_Unique(1);
$sa->Clear();
$sa->Append("apple");
$sa->Append("banana");
$sa->Append("apple");
$sa->Append("banana");

#  What do we have now?
print "-------- Unique strings:" . "\r\n";
$n = $sa->get_Count();
for ($i = 0; $i <= $n - 1; $i++) {
    print $sa->getString($i) . "\r\n";
}

#  Find the location of a specific string
#  (case insensitive).

$startIndex = 0;
$index = $sa->Find("apple",$startIndex);
if ($index >= 0) {
    print "found apple at index " . $index . "\r\n";
}
else {
    print "apple not found" . "\r\n";
}

 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.