String interpolation: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 1:
'''String interpolation''' is a form of [[Quasi-quotation]], common in many [[programming language]]s which make heavy use of [[String (computer science)|string]] representations of data, such as [[Python_(programming_language)|Python]], [[Ruby (programming language)|Ruby]], [[PHP]], [[Perl]], [[Nemerle]] etc. It means to insert a 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 133:
I have 4 apples
I have 7 fruits
</source>
 
=== Nemerle ===
<source lang="csharp">
def apples = 4;
def bananas = 3;
Console.WriteLine($"I have $apples apples");
Console.WriteLine($"I have $(apples + bananas) fruits");
</source>
 
You can also use advanced formatting features like this:
<source lang="csharp">
def fruits = ["apple", "banana"];
Console.WriteLine($<#I have ..$(fruits; "\n"; f => f + "s")#>);
</source>
 
The output will be:
<source lang="text">
apples
bananas
</source>