CorString: CopyTo |
Copies a specified number of characters from a specified position in a string to a specified position in an array of Unicode characters.
Public Sub CopyTo( ByRef Source As String, ByVal SourceIndex As Long, ByRef Destination ( ) As Integer, ByVal DestinationIndex As Long, ByVal Count As Long )
This method copies Count characters from the SourceIndex position of Source to the DestinationIndex position of destination character array. This method does not resize the destination character array; it must have a sufficient number of elements to accommodate the copied characters or the method throws an ArgumentOutOfRangeException.
SourceIndex is zero-based, and DestinationIndex is lower-bound based.
Exception | Condition |
---|---|
ArgumentNullException | Destination is null. |
ArgumentOutOfRangeException |
SourceIndex or Count is negative. -or- DestinationIndex is less than the lower-bound of Destination. -or- Count is greater than the length of the substring from StartIndex to the end of the string. -or- Count is greater than the length of the subarray from DestinationIndex to the upper-bound of the Destination array. |
The following example demonstrates the CopyTo method.
Public Sub Main() Dim StrSource As String Dim Destination() As Integer StrSource = "changed" Destination = NewChars("T", "h", "e", " ", "i", "n", "i", "t", "i", "a", "l", " ", "a", "r", "r", "a", "y") Debug.Print NewString(Destination) CorString.CopyTo StrSource, 0, Destination, 4, Len(StrSource) Debug.Print NewString(Destination) StrSource = "A different string" CorString.CopyTo StrSource, 2, Destination, 3, 9 Debug.Print NewString(Destination) End Sub ' This example produces the following output. ' ' The initial array ' The changed array ' Thedifferentarray