String mixin from within a template

ag0aep6g anonymous at example.com
Sun Aug 23 20:12:12 UTC 2020


On Sunday, 23 August 2020 at 19:42:47 UTC, data pulverizer wrote:
> `alias x` ~ i ~ ` = Remove(indexes[i] - i, x`~ (i - 1) ~ `);`
[...]
> ```d
> Error: no identifier for declarator x
> ```
>
> Indicating that the concatenation `~` is not working, and I 
> only get the partial string when I print out `pragma(msg, 
> _string_);`

You're having a misconception about concatenation.

This:

     "foo " ~ 65 ~ " bar"

does not produce the string "foo 65 bar". It produces the string 
"foo A bar", because 65 == 'A'. In your case, when i == 0, you 
get a null byte in the string, which is probably the cause for 
the partial output.

You can use std.conv or std.format to make a string from a number:

     text("foo ", 65, " bar")
     format("foo %s bar", 65)


More information about the Digitalmars-d-learn mailing list