Mid |
Description
Extracts a substring from a string.
Returns
A string; the set of characters from string, beginning at start, of length count.
Category
String functions
Function syntax
    Mid(string, start, count)
See also
Left, Len, Right
Parameters
Parameter | Description
string | A string or a variable that contains one. Must be single-quote or double-quote
| delimited.
start | A positive integer or a variable that contains one. Position at which to start count.
| Positions start with 1, not 0.
count | A positive integer or a variable that contains one. Number of characters to return. (0
| is not valid, but it does not throw an error.)
Example
    <h3>Mid 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> middle 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> middle characters:
          <cfoutput>#Mid(Form.myText, FORM.removeChars, Form.countChars)#</
    cfoutput>
          </cfif>

string |
A string or a variable that contains one. Must be single-quote or double-quote delimited.

start |
A positive integer or a variable that contains one. Position at which to start count. Positions start with 1, not 0.

count |
A positive integer or a variable that contains one. Number of characters to return. (0 is not valid, but it does not throw an error.)