View comments | RSS feed

Insert

Description

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

Return value

A string.

Category

String functions

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>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


tdkoll said on Oct 31, 2004 at 9:48 AM :
There seems to be a small error in the above example. The </cfif>
tag should not be placed above the <cfelse> tag, it is not loically
correct. It should be placed at the last line, for the example to work.
shawnwindler said on Nov 15, 2004 at 8:26 AM :
The </cfif> tag is placed at the end. There are two <cfif> statements, one of which is inside the other. The inner one ends before the <cfelse> of the outer <cfif>.
Kinda confusing how I just said that, but it makes sense to me. Just follow the code one line at a time, and you'll figure it out.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt1120.htm