CorString: Remove

Remove

Returns a new string in which a specified number of characters beginning at a specified position have been deleted.



 Public Function Remove(
	  ByRef s As String,
	  ByVal StartIndex As Long,
	  Optional ByRef Count As Variant ) As String

Parameters

s
[ByRef] String. The string to remove characters from.
StartIndex
[ByVal] Long. The zero-based position to begin deleting characters.
Count
[ByRef] Optional. Variant. The number of characters to delete.

Return Values

String -  A new string with the substring deleted.

Remarks

The value of the StartIndex parameter can range from zero to one less than the length of the string.
Note
This method does not modify the value of si. Instead, it returns a new string in which the number of characters specified by the count parameter have been removed. The characters are removed at the position specified by StartIndex.

Examples

The following example demonstrates how you can remove the middle name from a complete name.

Public Sub Main()
    Dim Name    As String
    Dim FoundS1 As Long
    Dim FoundS2 As Long
    
    Name = "Michelle Violet Banks"
    Debug.Print CorString.Format("The entire name is '{0}'", Name)
    
    FoundS1 = InStr(Name, " ")
    FoundS2 = InStr(FoundS1 + 1, Name, " ")
    
    If FoundS1 <> FoundS2 And FoundS1 > 0 Then
        Name = CorString.Remove(Name, FoundS1, FoundS2 - FoundS1)
        
        Debug.Print CorString.Format("After removing the middle name, we are left with '{0}'", Name)
    End If
End Sub

' This example produces the following output.
'
'    The entire name is 'Michelle Violet Banks'
'    After removing the middle name, we are left with 'Michelle Banks'

See Also

Project CorLib Overview

Class CorString Overview

Insert