string to char[4] FourCC conversion

realhet real_het at hotmail.com
Fri May 26 14:02:48 UTC 2023


On Friday, 26 May 2023 at 13:18:15 UTC, Steven Schveighoffer 
wrote:

> This worked for me:
>
> ```d
> char[4] fourC(string s)
> {
>     if(s.length >= 4)
>         return s[0 .. 4];
>     char[4] res = 0;
>     res[0 .. s.length] = s;
>     return res;
> }
> ```
Sometimes I forget that the return does an implicit cast. And it 
looks inside the slice [..] if it constant or not. Lot of things 
going on under the hood...

Thank You!


More information about the Digitalmars-d-learn mailing list