String.trimStart Function

Removes leading white-space characters from a String object.

var trimmedStringVar = myString.trimStart();

Return Value

A copy of the string with all white-space characters removed from the start of the string.


Use the trimStart function to remove leading white-space characters from the current String object. Examples of white-space characters are spaces and tabs.


The following example shows how to use the trimStart function to remove leading white space from a current String object.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head id="Head1" runat="server">
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">

        <script type="text/javascript">
            // Determines if a string has a specific prefix as 
            // the first non white-space characters in a string.
            function verifyString(myString, prefix) 
                // Remove any white space at the left of the string.
                myString = myString.trimStart();

                // Set to lower case.
                myString = myString.toLowerCase();

                // Determine if the string starts with the specified prefix.
                var hasPrefix = myString.startsWith(prefix.toString());
                if (hasPrefix === true)
                    alert("The string \"" + myString + "\" starts with \"" + prefix + "\""); 
                   alert("The string \"" + myString + " does not start with \"" + prefix + "\""); 

            // Displays: The string "green_blue_red" starts with "green"
            verifyString("  GREEN_BLUE_RED  ", "green");


See Also


String.trimEnd Function

Other Resources

Language Reference