Want to try out string interpolation in D?

Imperatorn johan_forsberg_86 at hotmail.com
Fri Oct 20 16:41:40 UTC 2023


Here's a script to get you started

```bash
git clone https://github.com/adamdruppe/dmd.git
cd dmd
git checkout interp
rdmd compiler/src/build.d
```

I don't want to copy files anywhere, so the user has to do that 
manually:

Copy dmd from the generated executable to your D bin installation 
folder

Example:
```
copy generated\windows\release\64\dmd.exe C:\d\dmd2\windows\bin64
```

Copy druntime/src/core/interpolation.d to your corresponding 
druntime folder + import

Example:
```
copy druntime/src/core/interpolation.d 
C:\d\dmd2\src\druntime\import\core\
```

Now try string interpolation:

```d
import std.stdio;

void main()
{
	string name = "Johan";
	int age = 37;
	int iq = 8001;
	int coffees = 1000;

	writeln(i"Your name is $name and you're $age years old");
	writeln(i"You drink $coffees cups a day and it gives you 
$(coffees + iq) IQ");
}
```

Output:
```
Your name is Johan and you're 37 years old
You drink 1000 cups a day and it gives you 9001 IQ
```


More information about the Digitalmars-d-learn mailing list