Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
The Chilkat StringArray objectThe 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. LOCAL loSa LOCAL n LOCAL i LOCAL lnAscending LOCAL lnUseCrlf LOCAL lcSerialized LOCAL loSa2 LOCAL lnIndex LOCAL lnStartIndex * This is not an array -- it's an object. loSa = CreateObject('Chilkat.CkStringArray') * Append some strings. loSa.Append("abc") loSa.Append("Abc") loSa.Append("123") loSa.Append("Chilkat Software, Inc.") * How many strings? n = loSa.Count ? STR(n) * Iterate over the strings contained in the object: FOR i = 0 TO n - 1 ? loSa.GetString(i) NEXT * Sort in ascending order: lnAscending = 1 loSa.Sort(lnAscending) ? "Sorted:" FOR i = 0 TO n - 1 ? loSa.GetString(i) NEXT * Save to a file (one string per line). * Line endings are controlled by the Crlf property. lnUseCrlf = 1 loSa.Crlf = lnUseCrlf loSa.SaveToFile("strings.txt") * Clear the string array. loSa.Clear() * Load the string array from a file. Each line in the * file becomes a string contained in the object: loSa.LoadFromFile("strings.txt") * Remove a string by exact match: loSa.Remove("abc") * Remove a string by index (1st string is at index 0): loSa.RemoveAt(2) * The Trim property can be set to automatically trim whitespace * from the beginning and end of any string added to the object: loSa.Trim = 1 * Append some strings from a comma-separated list: loSa.SplitAndAppend("apple, orange, banana, pear, lime",",") * What do we have now? ? "-------- After SplitAndAppend:" n = loSa.Count FOR i = 0 TO n - 1 ? loSa.GetString(i) NEXT * Serialize the complete object to a base64 string: lcSerialized = loSa.Serialize() ? "-------- Serialized:" ? lcSerialized * Restore from a serialized string: loSa2 = CreateObject('Chilkat.CkStringArray') loSa2.AppendSerialized(lcSerialized) ? "-------- After AppendSerialized:" n = loSa2.Count FOR i = 0 TO n - 1 ? loSa2.GetString(i) NEXT * Set the Unique property to prevent duplicates from being added: loSa.Unique = 1 loSa.Clear() loSa.Append("apple") loSa.Append("banana") loSa.Append("apple") loSa.Append("banana") * What do we have now? ? "-------- Unique strings:" n = loSa.Count FOR i = 0 TO n - 1 ? loSa.GetString(i) NEXT * Find the location of a specific string * (case insensitive). lnStartIndex = 0 lnIndex = loSa.Find("apple",lnStartIndex) IF (lnIndex >= 0) THEN ? "found apple at index " + STR(lnIndex) ELSE ? "apple not found" ENDIF |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser