How to parse enum from a string ?

Vinod K Chandran kcvinu82 at gmail.com
Wed May 27 18:09:45 UTC 2020


On Wednesday, 27 May 2020 at 17:36:35 UTC, Dennis wrote:
> On Wednesday, 27 May 2020 at 17:33:33 UTC, Vinod K Chandran 
> wrote:
>> I am saving this enum values as string in database. So, when i 
>> retrieve them from the database, how can i parse the string 
>> into TestEnum ?
>
> Use `to` from `std.conv`.
>
> ```
> import std.conv: to;
> void main() {
>     assert("Received".to!TestEnum == TestEnum.Received);
> }
> ```

Hi,
Thanks a lot. It worked. :)


More information about the Digitalmars-d-learn mailing list