String interpolation: Difference between revisions

Content deleted Content added
Add a Python sample
added coldfusion and cfml example
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 --->
<cfset name = "Dan" />
<cfset fruit = ['apples', 'pears', 'bananas'] />
<cfset phrase = "I have #arraylen(fruit)# types of fruit, such as #fruit[1]#" />
 
<cfoutput>
<p>Hi #Dan#,</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>
</cfoutput>
</source>