# \#string-interpolation

**URL:** https://discourse.julialang.org/tag/string-interpolation/922.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [\_str string interpolation?](https://discourse.julialang.org/t/str-string-interpolation/125766)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 12\
**Last updated:** [February 11, 2025, 7:55pm UTC](https://discourse.julialang.org/t/str-string-interpolation/125766 "2025-02-11T19:55:43Z")

</div>

I am not sure what is the issue, but I would like to this to work: julia\> macro test\_str(s) :($(esc(s))) end @test\_str (macro with 1 method) julia\> test"a 1" # "works" "a 1" julia\> i = 1 1 julia\> t…

---

## [Make ProgressMeter description display depends on a for-loop variable](https://discourse.julialang.org/t/make-progressmeter-description-display-depends-on-a-for-loop-variable/117509)

<div class="topic-metadata">

**Author:** [@K5Julien](https://discourse.julialang.org/u/K5Julien)\
**Replies:** 3\
**Last updated:** [July 27, 2024, 12:49pm UTC](https://discourse.julialang.org/t/make-progressmeter-description-display-depends-on-a-for-loop-variable/117509 "2024-07-27T12:49:53Z")

</div>

The following works well: using ProgressMeter @showprogress dt=1 desc="Computing ..." for c in 1:100\_000 # Some computing end However, I’d like the description to display some string that depends on c: using Progr…

---

## [String interpolation formatting](https://discourse.julialang.org/t/string-interpolation-formatting/91454)

<div class="topic-metadata">

**Author:** [@Nathaniel](https://discourse.julialang.org/u/Nathaniel)\
**Replies:** 13\
**Last updated:** [February 15, 2024, 7:52pm UTC](https://discourse.julialang.org/t/string-interpolation-formatting/91454 "2024-02-15T19:52:47Z")

</div>

Consider println("The square root of pi is $(sqrt(pi))") which displays The square root of pi is 1.7724538509055159 How can I change this code if I only want to print the answer to (say) two decimal places? I know t…

---

## [Syntax error: 'invalid interpolation syntax' when using include()](https://discourse.julialang.org/t/syntax-error-invalid-interpolation-syntax-when-using-include/52732)

<div class="topic-metadata">

**Author:** [@MattWillFlood](https://discourse.julialang.org/u/MattWillFlood)\
**Replies:** 4\
**Last updated:** [July 14, 2022, 10:19am UTC](https://discourse.julialang.org/t/syntax-error-invalid-interpolation-syntax-when-using-include/52732 "2022-07-14T10:19:24Z")

</div>

Hi Guys, I’m new-ish to Julia and so far things have been great, but this syntax error has really stumped me. :man\_shrugging:t3: Here’s the background. I have several files called \_Aa.jl, \_Bb.jl, and so on. Each one…

---

## [Parse constant from enviroment - macro parameter string interpolation](https://discourse.julialang.org/t/parse-constant-from-enviroment-macro-parameter-string-interpolation/81133)

<div class="topic-metadata">

**Author:** [@FireCrumb](https://discourse.julialang.org/u/FireCrumb)\
**Replies:** 3\
**Last updated:** [May 16, 2022, 8:01am UTC](https://discourse.julialang.org/t/parse-constant-from-enviroment-macro-parameter-string-interpolation/81133 "2022-05-16T08:01:18Z")

</div>

I have some global constants which I want to read from ENV or define with a default value. I pass a parameter to the macro and want to put it into a string in the output expression. When I use "$($name)" then I get "$(…

---

## [Broadcasting string interpolation](https://discourse.julialang.org/t/broadcasting-string-interpolation/78025)

<div class="topic-metadata">

**Author:** [@nielsls](https://discourse.julialang.org/u/nielsls)\
**Replies:** 2\
**Last updated:** [March 17, 2022, 1:16pm UTC](https://discourse.julialang.org/t/broadcasting-string-interpolation/78025 "2022-03-17T13:16:19Z")

</div>

Currently, this does not work: julia\> is = \[1,2\] 2-element Vector{Int64}: 1 2 julia\> "$.is" # currently a syntax error 2-element Vector{String}: "1" "2" But it should, right? For completeness sake? Allowing $. a…

---

## [Variables used in string interpolations are not recognized as used by vscode extension](https://discourse.julialang.org/t/variables-used-in-string-interpolations-are-not-recognized-as-used-by-vscode-extension/54753)

<div class="topic-metadata">

**Author:** [@Telcrome](https://discourse.julialang.org/u/Telcrome)\
**Replies:** 0\
**Last updated:** [February 6, 2021, 7:54pm UTC](https://discourse.julialang.org/t/variables-used-in-string-interpolations-are-not-recognized-as-used-by-vscode-extension/54753 "2021-02-06T19:54:48Z")

</div>

When defining this function in the vscode extension function ping(website::String, count::Int)::String return read(\`ping $(website) -c $(count)\`, String); end The extension does not recognize the usage of the argum…

---

## [Plots: string interpolation in labels?](https://discourse.julialang.org/t/plots-string-interpolation-in-labels/10799)

<div class="topic-metadata">

**Author:** [@BLI](https://discourse.julialang.org/u/BLI)\
**Replies:** 3\
**Last updated:** [January 18, 2022, 3:22pm UTC](https://discourse.julialang.org/t/plots-string-interpolation-in-labels/10799 "2022-01-18T15:22:35Z")

</div>

I’m solving a differential equation several times where I vary a parameter, say Kp = linspace(1,5,5). The result is a vector of vectors (time series), say vec is a vector (1D array) of vectors (time series). I then want…

---

## [Interpolation inside string inside quote](https://discourse.julialang.org/t/interpolation-inside-string-inside-quote/74791)

<div class="topic-metadata">

**Author:** [@circonflexe](https://discourse.julialang.org/u/circonflexe)\
**Replies:** 1\
**Last updated:** [January 18, 2022, 10:27am UTC](https://discourse.julialang.org/t/interpolation-inside-string-inside-quote/74791 "2022-01-18T10:27:09Z")

</div>

macro test() name="foo" quote "a string containing $name" end end On running this macro I would expect to receive “a string containing foo”. However all I get is UndefVarError: name not defined. How could I t…

---

## [Modify string interpolation](https://discourse.julialang.org/t/modify-string-interpolation/72904)

<div class="topic-metadata">

**Author:** [@Asmund\_Hjulstad](https://discourse.julialang.org/u/Asmund_Hjulstad)\
**Replies:** 4\
**Last updated:** [December 12, 2021, 2:01pm UTC](https://discourse.julialang.org/t/modify-string-interpolation/72904 "2021-12-12T14:01:09Z")

</div>

Is it possible to modify string interpolation using type-specific rules restricted to a specific context? """SELECT \* WHERE { ?s \<$(ns.aa.\_\_str\_\_())\> ?o) } """ outputs "SELECT \* WHERE {\\n?s \<http://example.org/aa\> ?o)…

---

## [Interpolation to any string](https://discourse.julialang.org/t/interpolation-to-any-string/71020)

<div class="topic-metadata">

**Author:** [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Replies:** 6\
**Last updated:** [November 6, 2021, 7:05pm UTC](https://discourse.julialang.org/t/interpolation-to-any-string/71020 "2021-11-06T19:05:11Z")

</div>

Hi, is it possible to create a universal function to interpolation to any string? maybe there is a function to pass values to the template one at time? teplate = "\\$str1 \\$str2" function get\_text\_by\_template(teplate; …

---

## [Variable interpolation in string within expression](https://discourse.julialang.org/t/variable-interpolation-in-string-within-expression/70258)

<div class="topic-metadata">

**Author:** [@disberd](https://discourse.julialang.org/u/disberd)\
**Replies:** 2\
**Last updated:** [October 23, 2021, 9:58am UTC](https://discourse.julialang.org/t/variable-interpolation-in-string-within-expression/70258 "2021-10-23T09:58:38Z")

</div>

Hi there, I am experimenting a bit with macros and wanted to know wheter there is a way to interpolate a variable (that is local to the macro) value inside a string within an expression returned by the macro. a MWE is …

---

## [String interpolation in markdown admonition in Pluto](https://discourse.julialang.org/t/string-interpolation-in-markdown-admonition-in-pluto/63795)

<div class="topic-metadata">

**Author:** [@dpkwhan](https://discourse.julialang.org/u/dpkwhan)\
**Replies:** 2\
**Last updated:** [July 11, 2021, 2:41am UTC](https://discourse.julialang.org/t/string-interpolation-in-markdown-admonition-in-pluto/63795 "2021-07-11T02:41:43Z")

</div>

In Pluto, the following code snippet fails to properly interpolate the values. How to fix it? begin todo\_index = 3 md""" !!! todo "Todo $(todo\_index)" This is todo #$(todo\_index) """ end

---

## [Is there any way in Julia to perform string interpolation after the string is decl](https://discourse.julialang.org/t/is-there-any-way-in-julia-to-perform-string-interpolation-after-the-string-is-decl/55688)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 1\
**Last updated:** [February 20, 2021, 5:37pm UTC](https://discourse.julialang.org/t/is-there-any-way-in-julia-to-perform-string-interpolation-after-the-string-is-decl/55688 "2021-02-20T17:37:12Z")

</div>

Is there any way in Julia to perform string interpolation after the string is declared? For example in python I can do: &gt; x = "Hello, {}" &gt; x.format("friend") 'Hello, friend' So I can declare x with placeholders…

---

## [String Interpolation Question](https://discourse.julialang.org/t/string-interpolation-question/52752)

<div class="topic-metadata">

**Author:** [@Bryan\_So](https://discourse.julialang.org/u/Bryan_So)\
**Replies:** 4\
**Last updated:** [January 4, 2021, 7:14pm UTC](https://discourse.julialang.org/t/string-interpolation-question/52752 "2021-01-04T19:14:42Z")

</div>

HI, very simple beginner’s question about string interpolation: If a variable is a struct that has a Base.string method. Does string interpolation use that method? This is most curious: struct Expression\_Symbol d…

---

## [String interpolation in the short-hand call of macro @bash1\_str](https://discourse.julialang.org/t/string-interpolation-in-the-short-hand-call-of-macro-bash1-str/51846)

<div class="topic-metadata">

**Author:** [@Lian\_Yunlong](https://discourse.julialang.org/u/Lian_Yunlong)\
**Replies:** 2\
**Last updated:** [December 31, 2020, 3:01am UTC](https://discourse.julialang.org/t/string-interpolation-in-the-short-hand-call-of-macro-bash1-str/51846 "2020-12-31T03:01:54Z")

</div>

Hello everyone, I am trying to improve the following macro: macro bash1\_str(s1) s = eval(s1); println(s); open(bash,"w",stdout) do io; print(io, s); end; end ; If I call @bash1\_str "mkdir $FD" The string FD is inter…

---

## [How do I implement recursive interpolation ($) for string macros?](https://discourse.julialang.org/t/how-do-i-implement-recursive-interpolation-for-string-macros/50444)

<div class="topic-metadata">

**Author:** [@cce](https://discourse.julialang.org/u/cce)\
**Replies:** 4\
**Last updated:** [November 20, 2020, 2:57am UTC](https://discourse.julialang.org/t/how-do-i-implement-recursive-interpolation-for-string-macros/50444 "2020-11-20T02:57:49Z")

</div>

Could Meta.parse grow an option to re-use $ interpolation semantics within a string macro? I’m trying to replicate functionality of Mike Bostock’s Hyper Text Literal only ported to Julia (HypertextLiteral.jl). Specific…

---

## [String interpolation in docstring](https://discourse.julialang.org/t/string-interpolation-in-docstring/48371)

<div class="topic-metadata">

**Author:** [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Replies:** 10\
**Last updated:** [October 15, 2020, 9:11am UTC](https://discourse.julialang.org/t/string-interpolation-in-docstring/48371 "2020-10-15T09:11:57Z")

</div>

Hey community :slight\_smile: That’s probably a quick question. I’m writing docstrings and want to show an little example like """ f(s::String)::Nothing # Example for i in 1:10 f("i = $i") end """ function f(s::…

---

## [How to read a string from a file with interpolation](https://discourse.julialang.org/t/how-to-read-a-string-from-a-file-with-interpolation/47913)

<div class="topic-metadata">

**Author:** [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Replies:** 7\
**Last updated:** [October 7, 2020, 8:22pm UTC](https://discourse.julialang.org/t/how-to-read-a-string-from-a-file-with-interpolation/47913 "2020-10-07T20:22:02Z")

</div>

The file “test.txt” contains a single line: I am $me The following is intended to simply read the string and store the interpolated result in str: me = "Sam" str = read("test.txt", String); str == "I am Sam" false

---

## [Formatted string interpolation](https://discourse.julialang.org/t/formatted-string-interpolation/21350)

<div class="topic-metadata">

**Author:** [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Replies:** 6\
**Last updated:** [September 7, 2020, 7:11am UTC](https://discourse.julialang.org/t/formatted-string-interpolation/21350 "2020-09-07T07:11:47Z")

</div>

I’m currently looking for a package providing format options when interpolating values in a string, like e.g. in python: f'abc {x:.2f} def'. StringLiterals from JuliaString (GitHub - JuliaString/StringLiterals.jl: Implem…

---

## [DocStringExtensions - interpolation string "$" allowed only in the preamble but not inside the structure](https://discourse.julialang.org/t/docstringextensions-interpolation-string-allowed-only-in-the-preamble-but-not-inside-the-structure/40349)

<div class="topic-metadata">

**Author:** [@yurier](https://discourse.julialang.org/u/yurier)\
**Replies:** 2\
**Last updated:** [May 29, 2020, 11:34am UTC](https://discourse.julialang.org/t/docstringextensions-interpolation-string-allowed-only-in-the-preamble-but-not-inside-the-structure/40349 "2020-05-29T11:34:39Z")

</div>

I would like to pass a function to some docstrings inside a structure (by using $) not only in the preamble as in the example. works without $ inside the structure using Parameters, DocStringExtensions """ # My parame…

---

## [A string interpolation inconsistency](https://discourse.julialang.org/t/a-string-interpolation-inconsistency/14042)

<div class="topic-metadata">

**Author:** [@sswatson](https://discourse.julialang.org/u/sswatson)\
**Replies:** 10\
**Last updated:** [August 27, 2018, 7:34pm UTC](https://discourse.julialang.org/t/a-string-interpolation-inconsistency/14042 "2018-08-27T19:34:48Z")

</div>

It seems that string interpolation works differently depending on whether the string consists entirely of a single interpolation: struct Foo a::String end import Base.string string(F::Foo) = F.a F = Foo("bar") "$…

---

## [Pass interpolating string to macro](https://discourse.julialang.org/t/pass-interpolating-string-to-macro/13876)

<div class="topic-metadata">

**Author:** [@ulysses](https://discourse.julialang.org/u/ulysses)\
**Replies:** 2\
**Last updated:** [August 22, 2018, 3:39pm UTC](https://discourse.julialang.org/t/pass-interpolating-string-to-macro/13876 "2018-08-22T15:39:57Z")

</div>

I’m trying to define basic macro but fail: macro mydebug(s) :(println($s)) end function main() i = 42 @mydebug("$(i)") end This one yield: UndefVarError: i not defined Is it not possible to pass interpolating …

---

## [Can I interpolate a string in a regular expression?](https://discourse.julialang.org/t/can-i-interpolate-a-string-in-a-regular-expression/10763)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 3\
**Last updated:** [May 7, 2018, 5:39pm UTC](https://discourse.julialang.org/t/can-i-interpolate-a-string-in-a-regular-expression/10763 "2018-05-07T17:39:14Z")

</div>

As in the title, how can I make the code below match? a = "a" ismatch(r"th$(a)t", "this that") # returns false The problem is that $ has a meaning in a regular expression, but is also used for interpolating strings in…

---

## [String interpolation not working in julia pipe to julia !?!](https://discourse.julialang.org/t/string-interpolation-not-working-in-julia-pipe-to-julia/6385)

<div class="topic-metadata">

**Author:** [@TravisA9](https://discourse.julialang.org/u/TravisA9)\
**Replies:** 3\
**Last updated:** [October 11, 2017, 4:16pm UTC](https://discourse.julialang.org/t/string-interpolation-not-working-in-julia-pipe-to-julia/6385 "2017-10-11T16:16:52Z")

</div>

I was playing around a bit here on an idea based on an unanswered question I found on stackoverflow. Namely this one: Julia - pipe to Julia REPL - Stack Overflow The following is related and has a more direct answer: …

---

## [Regex w/ String Interpolation](https://discourse.julialang.org/t/regex-w-string-interpolation/3545)

<div class="topic-metadata">

**Author:** [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Replies:** 1\
**Last updated:** [May 5, 2017, 9:13pm UTC](https://discourse.julialang.org/t/regex-w-string-interpolation/3545 "2017-05-05T21:13:53Z")

</div>

I want to do something along the lines of: a = "focus" ismatch(r"$(a)\\s\*:\\s\*true", "# focus: true") But this doesnt work // probably similar to issue #1797 What is the correct way to do this? eval( parse( "ismatch(r…
