CorString: ToCharArray |
Creates and array of chars (Integers) from the specified string.
Public Function ToCharArray( ByRef s As String, Optional ByRef StartIndex As Variant, Optional ByRef Length As Variant ) As Integer ( )
The StartIndex parameter is zero-based. That is, the index of the first character in the string s is zero.
If Length is zero, the returned array is empty and has a zero length. If s is an empty string (""), the returned array is empty and has a zero length.
Exception | Condition |
---|---|
ArgumentOutOfRangeException |
StartIndex or Length is less than zero. -or- StartIndex plus Length is greater than the length of s. |
The following example converts a substring within a string to an array of characters, then enumerates and displays the elements of the array.
Public Sub Main() Const Str As String = "012wxyz789" Dim Arr() As Integer Arr = CorString.ToCharArray(Str, 3, 4) Debug.Print CorString.Format("The letters in '{0}' are: '{1}'", Str, NewString(Arr)) Debug.Print CorString.Format("Each letter in '{0}' is:", Str) Dim c As Variant For Each c In Arr Debug.Print ChrW$(c) Next End Sub ' This code produces the following output. ' ' The letters in '012wxyz789' are: 'wxyz' ' Each letter in '012wxyz789' is: ' w ' x ' y ' z