digitalmars.D.learn - String representation of enum value
- Marek Janukowicz (12/12) Aug 04 2013 Given following code:
- Robik (3/16) Aug 04 2013 I think std.conv.to!string is what are you looking for :)
- Marek Janukowicz (4/7) Aug 04 2013 Wow, so simple, thanks
Given following code:
enum ErrorCode {
BAD_REQUEST,
UNKNOWN
}
ErrorCode code;
is there any way to get string representation of code with regard to values
defined in enum? I mean - if code == 0, I'd like to get a string
"BAD_REQUEST", if it's == 1, I'd like to get string a "UNKNOWN". Of course
I'd like to use something more consise and elegant than a switch :)
--
Marek Janukowicz
Aug 04 2013
On Sunday, 4 August 2013 at 13:57:20 UTC, Marek Janukowicz wrote:
Given following code:
enum ErrorCode {
BAD_REQUEST,
UNKNOWN
}
ErrorCode code;
is there any way to get string representation of code with
regard to values
defined in enum? I mean - if code == 0, I'd like to get a string
"BAD_REQUEST", if it's == 1, I'd like to get string a
"UNKNOWN". Of course
I'd like to use something more consise and elegant than a
switch :)
I think std.conv.to!string is what are you looking for :)
http://dpaste.dzfl.pl/e1c38f8f
Aug 04 2013
Robik wrote:I think std.conv.to!string is what are you looking for :) http://dpaste.dzfl.pl/e1c38f8fWow, so simple, thanks -- Marek Janukowicz
Aug 04 2013








Marek Janukowicz <marek janukowicz.net>