Just another example of missing string interpolation
kdevel
kdevel at vogtner.de
Fri Oct 13 11:14:01 UTC 2023
On Thursday, 12 October 2023 at 13:39:46 UTC, Andrea Fontana
wrote:
> Real life example. Render a string like this:
>
> ```
> \x1b[2K\r\x1b[1mProgress:\x1b[0m 50% \x1b[1m\tSpeed:\x1b[0m
> 15.5 KB/s
> ```
>
> now (error prone and difficult to debug, try to code it!):
Where is the specific problem?
```
import std.stdio;
int main (string [] args)
{
enum fmt = "\x1b[2K\r\x1b[1mProgress:\x1b[0m %s%%
\x1b[1m\tSpeed:\x1b[0m > %s KB/s";
writeln (fmt);
writefln!fmt (75, 11.11);
return 0;
}
$ ./prgs
Progress: %s%% Speed: > %s KB/s
Progress: 75% Speed: > 11.11 KB/s
```
The words `Progress` and `Speed` appear highlighted in my console.
More information about the Digitalmars-d
mailing list