left

Description

Returns the leftmost count characters in a string.

Categories

Related

Syntax

Left(string, count)

Attributes

AttributeDescriptionRequiredDefault
countA positive integer or a variable that contains one. Number of characters to return.
stringA string or a variable that contains one.

Returns

String; the first count characters in the string parameter.

Example

<h3>Left Example</h3> 
 
<cfif IsDefined("Form.myText")> 
<!--- If len returns 0 (zero), then show error message. ---> 
    <cfif Len(Form.myText)> 
        <cfif Len(Form.myText) LTE Form.RemoveChars> 
            <cfoutput><p style="color: red; font-weight: bold">Your string #Form.myText# only has #Len(Form.myText)# characters. You cannot output  
    the #Form.removeChars# leftmost characters of this string because it is  
    not long enough.</p></cfoutput> 
        <cfelse> 
            <cfoutput>Your original string: <strong>#Form.myText#</strong></p> 
                Your changed string, showing only the <strong>#Form.removeChars# 
                    </strong> leftmost characters: 
                    <strong>#Left(Form.myText, Form.removeChars)#</strong></p> 
            </cfoutput> 
        </cfif> 
    <cfelse> 
        <p style="color: red; font-weight: bold">Please enter a string of more than 0 (zero) characters.</p> 
</cfif> 
</cfif> 
 
<form action="<cfoutput>#CGI.ScriptName#</cfoutput>" method="POST"> 
Type in some text<br /> 
<input type="Text" name="myText"></p> 
How many characters from the left do you want to show? 
<select name="RemoveChars"> 
<option value="1">1 
<option value="3" selected>3 
<option value="5">5 
<option value="7">7 
<option value="9">9</select> 
<input type="Submit" name="Submit" value="Remove characters"></p> 
</form>