Left

Returns the leftmost count characters in a string.

String; the first count characters in the string parameter.

String functions

Left(string, count)

Right, Mid, Len

Parameter Description

string

A string or a variable that contains one.

count

A positive integer or a variable that contains one. Number of characters to return.

<h3>Left Example</h3>

<cfif IsDefined("Form.MyText")>
<!--- if len is 0, then err --->
   <cfif Len(form.myText) is not 0>
      <cfif Len(form.myText) LTE form.RemoveChars>
         <p>Your string <cfoutput>#form.myText#</cfoutput>
         only has <cfoutput>#Len(form.myText)#</cfoutput>
         characters. You cannot output the <cfoutput>#form.removeChars#</cfoutput>
         leftmost characters of this string because it is not long enough
      <cfelse>
         <p>Your original string: <cfoutput>#form.myText#</cfoutput>
         <p>Your changed string, showing only the <cfoutput>#form.removeChars#
</cfoutput> leftmost characters: <cfoutput>#Left(Form.myText, form.removeChars)#</cfoutput> </cfif> <cfelse> <p>Please enter a string </cfif> </cfif> <form action="#CGI.ScriptName#" method="POST"> <p>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="Remove characters"> </form>

View comments on LiveDocs