CorString: TrimStart

TrimStart

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



 Public Function TrimStart(
	  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 start 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 TrimStart method removes from s all leading 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 TrimStart method returns "abc456xyz789".

Note
This method does not modify the s parameter. Instead, it returns a new string in which all leading 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 leading 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.TrimStart(Str, Digits)
    Debug.Print CorString.TrimStart(Str, DigitChars)
End Sub

' The previous code outputs the following.
'
'    abcx987234
'    abcx987234

See Also

Project CorLib Overview

Class CorString Overview

Trim

TrimEnd

ToCharArray