String interpolation: Difference between revisions

Content deleted Content added
m Reverting possible vandalism by 98.169.42.55 to older version. False positive? Report it. Thanks, ClueBot NG. (988621) (Bot)
Line 1:
{{Orphan|date=February 2011}}
 
'''String interpolation''' is a common feature in many [[programming language]]s such as [[Ruby (programming language)|Ruby]], [[PHP]], [[Perl]], [[ColdFusion]], etc. It means to insert a [[String (computer science)|string]] or replace a variable with its value. It makes string formatting and specifying contents more intuitive.<ref>http://perlmeme.org/howtos/using_perl/interpolation.html</ref>
 
== Examples ==
Line 53:
<source lang="text">
I have 4 apples
</source>
 
=== ColdFusion ===
<source lang="cfm">
<!--- variable and expressions can be added
during string creation and output by surrounding in pound signs (#) --->
<cfset name = "Dan" />
<cfset fruit = ['apples', 'pears', 'bananas'] />
<cfset phrase = "I have #arraylen(fruit)# types of fruit, such as #fruit[1]#" />
 
<cfoutput>
<p>Hi #name#,</p>
<p>I just wanted to let you know #phrase#.</p>
<p>Types:</p>
<ul>
<cfloop array="#fruit#" index="type">
<li>#type#</li>
</cfloop>
</ul>
<p><em>Information valid as of #dateformat(now(), "mm/dd/yyyy")#</em></p>
</cfoutput>
</source>
The output will be:
<source lang="text">
<p>Hi Dan,</p>
<p>I just wanted to let you know I have 3 types of fruit, such as apples.</p>
<p>Types:</p>
<ul>
<li>apples</li>
<li>pears</li>
<li>bananas</li>
</ul>
<p><em>Information valid as of 3/31/2012</em></p>
</source>