Insert

Description

Inserts a substring in a string after a specified character position. If position = 0, prefixes the substring to the string.

Returns

A string.

Category

String functions

Function syntax

Insert(substring, string, position)

See also

RemoveChars, Len

Parameters

Parameter

Description

substring

A string or a variable that contains one. String to insert.

string

A string or a variable that contains one. String into which to insert substring.

position

Integer or variable; position in string after which to insert substring.

Example

<h3>Insert Example</h3>

<cfif IsDefined("FORM.myString")>
	<!--- if the position is longer than the length of the string, err --->
	<cfif FORM.insertPosition GT Len(MyString)>
		<cfoutput>
		<p>This string only has #Len(MyString)# characters; therefore, 
you cannot insert the substring #FORM.mySubString# at position
#FORM.insertPosition#. </cfoutput> </cfif> <cfelse> <cfoutput> <p>You inserted the substring #FORM.MySubstring# into the string
#FORM.MyString#, resulting in the following string:
<br>#Insert(FORM.MySubString, FORM.myString,
FORM.insertposition)
# </cfoutput> </cfif>