Concat enum of strings into one string
Mike Franklin
slavo5150 at yahoo.com
Tue Aug 14 13:45:48 UTC 2018
On Tuesday, 14 August 2018 at 13:42:04 UTC, Andrey wrote:
> Hello,
> I have a enum:
>
> enum Type : string
> {
> One = "Q1",
> Two = "W2",
> Three = "R3"
> }
>
> I want to concat it in compile-time:
>
> enum result = doConcat!Type();
>
> And get this result:
>
> writeln(result); // output: "Q1 W2 R3"
>
> Delimiter here is space symbol.
> How do do it?
I think you just need to use the concatenation operator `~`.
enum Type : string
{
One = "Q1",
Two = "W2",
Three = "R3"
}
enum concatenation = Type.One ~ " " ~ Type.Two ~ " " ~ Type.Three;
void main()
{
import std.stdio: writeln;
writeln(concatenation);
}
Mike
More information about the Digitalmars-d-learn
mailing list