Visual C++ Examples

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

C++ Examples

CkString
Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
DH Key Exchange
DKIM/DomainKeys
Digital Certificates
Digital Signatures
DSA
Email
Email Object
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
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.

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
#include <CkStringArray.h>
#include <CkString.h>

void ChilkatSample(void)
    {
    //  This is not an array -- it's an object.
    CkStringArray sa;

    //  Append some strings.
    sa.Append("abc");
    sa.Append("Abc");
    sa.Append("123");
    sa.Append("Chilkat Software, Inc.");

    //  How many strings?
    int n;
    n = sa.get_Count();
    printf("%d\n",n);

    //  Iterate over the strings contained in the object:
    int i;
    for (i = 0; i <= n - 1; i++) {
        printf("%s\n",sa.getString(i));
    }

    //  Sort in ascending order:
    bool ascending;
    ascending = true;
    sa.Sort(ascending);

    printf("Sorted:\n");
    for (i = 0; i <= n - 1; i++) {
        printf("%s\n",sa.getString(i));
    }

    //  Save to a file (one string per line).
    //  Line endings are controlled by the Crlf property.
    bool useCrlf;
    useCrlf = true;
    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(true);

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

    //  What do we have now?
    printf("-------- After SplitAndAppend:\n");
    n = sa.get_Count();
    for (i = 0; i <= n - 1; i++) {
        printf("%s\n",sa.getString(i));
    }

    //  Serialize the complete object to a base64 string:
    CkString serialized;
    serialized = sa.serialize();

    printf("-------- Serialized:\n");
    printf("%s\n",(const char *)serialized);

    //  Restore from a serialized string:
    CkStringArray sa2;
    sa2.AppendSerialized(serialized);

    printf("-------- After AppendSerialized:\n");
    n = sa2.get_Count();
    for (i = 0; i <= n - 1; i++) {
        printf("%s\n",sa2.getString(i));
    }

    //  Set the Unique property to prevent duplicates from being added:
    sa.put_Unique(true);
    sa.Clear();
    sa.Append("apple");
    sa.Append("banana");
    sa.Append("apple");
    sa.Append("banana");

    //  What do we have now?
    printf("-------- Unique strings:\n");
    n = sa.get_Count();
    for (i = 0; i <= n - 1; i++) {
        printf("%s\n",sa.getString(i));
    }

    //  Find the location of a specific string
    //  (case insensitive).
    int index;
    int startIndex;
    startIndex = 0;
    index = sa.Find("apple",startIndex);
    if (index >= 0) {
        printf("found apple at index %d\n",index);
    }
    else {
        printf("apple not found\n");
    }


    }

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

Mail Component · .NET Mail Component · XML Parser