CorString: CopyTo

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 )

Parameters

Source
[ByRef] String. The string to copy the characters from.
SourceIndex
[ByVal] Long. The zero-based index of the first character to copy.
Destination
[ByRef] Integer. An array of Unicode characters to which characters in the string are copied.
DestinationIndex
[ByVal] Long. The index in Destination as which the copy operation begins.
Count
[ByVal] Long. The number of characters in the string to copy to Destination.

Remarks

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.

Exceptions

Exception Condition
ArgumentNullExceptionDestination 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.

Examples

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

See Also

Project CorLib Overview

Class CorString Overview