CorString: TrimEnd

TrimEnd

Removes all trailing occurrences of a set of characters specified in an array from the s parameter.



 Public Function TrimEnd(
	  ByRef s As String,
	  Optional ByRef TrimChars As Variant ) As String

Parameters

s
[ByRef] String. The string to be trimmed.
TrimChars
[ByRef] Optional. Variant. An array of Unicode characters to remove. String and Integer() are accepted.

Return Values

String -  The string that remains after all occurrences of characters in the TrimChars parameter are removed from the end of s. If TrimChars is missing, white-space characters are removed instead.

Remarks

TrimChars can be either a String or an Integer(). If a String is passed in it will be treated as an Integer() and each character will be used separately.

The TrimEnd method removes from s all trailing characters that are in the TrimChars parameter. The trim operation stops when a character that is not in TrimChars is encountered. For example, if s is "123abc456xyz789" and TrimChars contains the digits from "1" through "9", the TrimEnd method returns "123abc456xyz".

Note
This method does not modify the s parameter. Instead, it returns a new string in which all trailing white-space characters found in s are removed.

Exceptions

Exception Condition
ArgumentExceptionTrimChars was not a String or Integer().

Examples

The following example demonstrates trimming the trailing characters defined by a String and an Integer().

Public Sub Main()
    Const Digits As String = "0123456789"
    Const Str As String = "324357abcx987234"
    Dim DigitChars() As Integer
    
    DigitChars = CorString.ToCharArray(Digits)
    
    Debug.Print CorString.TrimEnd(Str, Digits)
    Debug.Print CorString.TrimEnd(Str, DigitChars)
End Sub

' The previous code outputs the following.
'
'   324357abcx
'   324357abcx

See Also

Project CorLib Overview

Class CorString Overview

Trim

TrimStart

ToCharArray