convert between types

Lars Johansson lasse at 11dim.se
Mon Jan 12 15:48:22 UTC 2026


On Thursday, 8 January 2026 at 19:44:10 UTC, Steven Schveighoffer 
wrote:
> On Friday, 2 January 2026 at 15:30:06 UTC, Lars Johansson wrote:
>> On Friday, 2 January 2026 at 15:02:09 UTC, Kapendev wrote:
>>> On Friday, 2 January 2026 at 13:09:44 UTC, Lars Johansson 
>>> wrote:
>>>>     I'm writing a simple program just to get started (se 
>>>> below).
>>>>      mat[i][z] = z; this line generate following error:
>>>>      cannot implicitly convert expression `z` of type 
>>>> `ulong` to `char`
>>>
>>> Simple as:
>>>
>>> ```d
>>> mat[i][z] = cast(char) z;
>>> ```
>>
>> Hi thank you for your reply.
>> But that gives me a blank result (white space). I have to add 
>> '0' to get the 'source' value from the cast.
>
> ```d
> mat[i][z] = "0123456789"[z];
> ```
>
> Other than that, your solution is probably the best. Another 
> thing you can do is instead of casting,I will now write 
> someting  use `(z + '0') & 0x7f`.
>
> The above has the benefit that if you exceed the "expected" 
> limit, you will get an out of bounds error instead of garbage 
> characters.
>
> -Steve

Hi thanks for all answers. I wrote a 'life' game with raylib as 
gui output. This was a nice experience. I will now write 
something more useful a simple MySQL monitor for a Data Warehouse 
app. I can easily do this with a bash script but I will use D 
just for the hell of it.


More information about the Digitalmars-d-learn mailing list