Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.TrimStart Method

Removes all leading occurrences of a set of characters specified in an array from the current String object.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

'Declaration
Public Function TrimStart ( _
	ParamArray trimChars As Char() _
) As String
'Usage
Dim instance As String
Dim trimChars As Char()
Dim returnValue As String

returnValue = instance.TrimStart(trimChars)
public String TrimStart (
	char[] trimChars
)
public function TrimStart (
	... trimChars : char[]
) : String
Not applicable.

Parameters

trimChars

An array of Unicode characters to remove or a null reference (Nothing in Visual Basic).

Return Value

The string that remains after all occurrences of characters in the trimChars parameter are removed from the start of the current String object. If trimChars is a null reference (Nothing in Visual Basic), white-space characters are removed instead.

The TrimStart method removes from the current string 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 the current string is "123abc456xyz789" and trimChars contains the digits from '1' through '9', the TrimStart method returns "abc456xyz789".

For more information about which Unicode characters are categorized as white-space characters, see the Remarks section of the String.Trim method overload.

The following example uses the TrimStart method to trim white space and comment characters from lines of source code. The StripComments method wraps a call to TrimStart and passes it a character array that contains a space and the comment character (an apostrophe ( ' ) in Visual Basic and a slash ( / ) in C#). The TrimStart method is also called to remove leading white space when evaluating whether a string is a comment.

Imports System


Module Application

    Sub Main()
        ' Create a string that will be trimmed.
        Dim path As String = "c:/temp/"

        ' Create an array of characters 
        ' that represent characters to trim.
        Dim charsToTrim As Char() = {"c"c, ":"c}

        ' Trim the string.
        Dim trimmedPath As String = path.TrimStart(charsToTrim)

        Console.WriteLine("The trimmed value is: {0}.", trimmedPath)

        ' Create a string that will be trimmed.
        Dim pathWhitespace As String = "                        c:/temp/"

        ' Trim whitespaces by passing Nothing.
        Dim trimmedWhiteSpace As String = pathWhitespace.TrimStart(Nothing)

        Console.WriteLine("The trimmed value is: {0}.", trimmedWhiteSpace)

    End Sub
End Module
' This code example displays the following
' to the console:
'
' The trimmed value is: /temp/.


The following example then illustrates a call to the StripComments method.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

Show: