Content deleted Content added
m use en dashes instead of hyphens |
Citation bot (talk | contribs) Add: title, date. Changed bare reference to CS1/2. | Use this bot. Report bugs. | Suggested by Folkezoft | Linked from User:Folkezoft/sandbox | #UCB_webform_linked 829/978 |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1:
{{short description|Replacing placeholders in a string with values}}
In [[computer programming]], '''string interpolation''' (or '''variable interpolation''', '''variable substitution''', or '''variable expansion''') is the process of evaluating a [[string literal]] containing one or more [[Form (document)#Placeholders|placeholders]], yielding a result in which the placeholders are replaced with their corresponding values. It is a form of simple [[Template processor|template processing]]<ref>"[
String interpolation is an alternative to building string via [[concatenation]], which requires repeat quoting and unquoting;<ref>{{Cite web|url=http://perlmeme.org/howtos/using_perl/interpolation.html|title = Interpolation in Perl |date = 12 December 2024 |quote="This is much tidier than repeat uses of the '.' concatenation operator."}}</ref> or substituting into a [[printf format string]], where the variable is far from where it is used. Compare:
<syntaxhighlight lang="ruby">
apples = 4
Line 112:
=== Go ===
{{Main|Go (programming language)}}
{{as of|2025}}, Go does not have string interpolation. There have been some proposals for string interpolation, which have been rejected.<ref>{{cite web|url=https://github.com/golang/go/issues/34174 |title=proposal: Go 2: string interpolation #34174|website=[[GitHub]] }}</ref><ref>{{cite web|url=https://github.com/golang/go/issues/50554 |title=proposal: Go 2: string interpolation evaluating to string and list of expressions #50554|website=[[GitHub]] }}</ref><ref>{{Cite web |title=proposal: spec: add simple string interpolation similar to Swift · Issue #57616 · golang/go |url=https://github.com/golang/go/issues/57616 |access-date=2025-05-19 |website=GitHub |language=en}}</ref>
=== Groovy ===
Line 151:
</syntaxhighlight>
They were removed in Java 23 due to design issues.<ref>{{cite web | title=Significant Changes in the JDK | url=https://docs.oracle.com/en/java/javase/23/migrate/significant-changes-jdk-release.html }}</ref>
=== JavaScript ===
Line 317:
|title= The Python Tutorial: 7.1.1. Formatted String Literals}}</ref><ref>{{Cite web |url=https://docs.python.org/3/reference/lexical_analysis.html#f-strings |title=The Python Language Reference: 2.4.3. Formatted string literals}}</ref><ref>{{Cite web|url=https://www.python.org/dev/peps/pep-0498/|title = PEP 498 -- Literal String Interpolation}}</ref> Such a literal begins with an <code>f</code> or <code>F</code> before the opening quote, and uses braces for placeholders:
<syntaxhighlight lang="python">
print(f'I have {
</syntaxhighlight>
The output will be:
|