String.trimStart 함수

String 개체에서 선행 공백 문자를 제거합니다.

var trimmedStringVar = myString.trimStart();

선행 공백 문자가 모두 제거된 문자열입니다.

trimStart 함수를 사용하면 현재 String 개체에서 선행 공백 문자를 제거할 수 있습니다. 공백 문자에는 공백과 탭 등이 포함됩니다.

다음 예제에서는 trimStart 함수를 사용하여 현재 String 개체에서 선행 공백을 제거하는 방법을 보여 줍니다.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Sample</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>

        <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 + "\""); 
                }
                else
                {
                   alert("The string \"" + myString + " does not start with \"" + prefix + "\""); 
                }
             }

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

        </script>
    </form>
</body>
</html>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Sample</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>

        <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 + "\""); 
                }
                else
                {
                   alert("The string \"" + myString + " does not start with \"" + prefix + "\""); 
                }
             }

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

        </script>
    </form>
</body>
</html>



표시: