Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor


VB Strings
VB Byte Array

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

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.

'  This is not an array -- it's an object.
Dim sa As New CkStringArray

'  Append some strings.
sa.Append "abc"
sa.Append "Abc"
sa.Append "123"
sa.Append "Chilkat Software, Inc."

'  How many strings?
Dim n As Long
n = sa.Count
Text1.Text = Text1.Text & n & vbCrLf
Text1.Refresh

'  Iterate over the strings contained in the object:
Dim i As Long
For i = 0 To n - 1
    Text1.Text = Text1.Text & sa.GetString(i) & vbCrLf
    Text1.Refresh
Next

'  Sort in ascending order:
Dim ascending As Long
ascending = 1
sa.Sort ascending

Text1.Text = Text1.Text & "Sorted:" & vbCrLf
Text1.Refresh
For i = 0 To n - 1
    Text1.Text = Text1.Text & sa.GetString(i) & vbCrLf
    Text1.Refresh
Next

'  Save to a file (one string per line).
'  Line endings are controlled by the Crlf property.
Dim useCrlf As Long
useCrlf = 1
sa.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.Trim = 1

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

'  What do we have now?
Text1.Text = Text1.Text & "-------- After SplitAndAppend:" & vbCrLf
Text1.Refresh
n = sa.Count
For i = 0 To n - 1
    Text1.Text = Text1.Text & sa.GetString(i) & vbCrLf
    Text1.Refresh
Next

'  Serialize the complete object to a base64 string:
Dim serialized As String
serialized = sa.Serialize()

Text1.Text = Text1.Text & "-------- Serialized:" & vbCrLf
Text1.Refresh
Text1.Text = Text1.Text & serialized & vbCrLf
Text1.Refresh

'  Restore from a serialized string:
Dim sa2 As New CkStringArray
sa2.AppendSerialized serialized

Text1.Text = Text1.Text & "-------- After AppendSerialized:" & vbCrLf
Text1.Refresh
n = sa2.Count
For i = 0 To n - 1
    Text1.Text = Text1.Text & sa2.GetString(i) & vbCrLf
    Text1.Refresh
Next

'  Set the Unique property to prevent duplicates from being added:
sa.Unique = 1
sa.Clear 
sa.Append "apple"
sa.Append "banana"
sa.Append "apple"
sa.Append "banana"

'  What do we have now?
Text1.Text = Text1.Text & "-------- Unique strings:" & vbCrLf
Text1.Refresh
n = sa.Count
For i = 0 To n - 1
    Text1.Text = Text1.Text & sa.GetString(i) & vbCrLf
    Text1.Refresh
Next

'  Find the location of a specific string
'  (case insensitive).
Dim index As Long
Dim startIndex As Long
startIndex = 0
index = sa.Find("apple",startIndex)
If (index >= 0) Then
    Text1.Text = Text1.Text & "found apple at index " _
         & index & vbCrLf
    Text1.Refresh
Else
    Text1.Text = Text1.Text & "apple not found" & vbCrLf
    Text1.Refresh
End If

Need a specific example? Send a request to support@chilkatsoft.com

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