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];
Silent truncation? Non-ASCII chars?
char[4] res = 0;
According to [1], [2] or [3] that should read
```
char[
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
On 5/26/23 8:19 AM, realhet wrote:
Hello,
Is there a way to do it nicer/better/faster/simpler?
```
char[4] fourC(string s)
{
uint res;//Zero initialized, not 0xff initialized.
auto cnt = min(s.length, 4),
p = cast(char[4]*)(&res);
(*p)[0..cnt] = s[0..cnt];
retur
Hello,
Is there a way to do it nicer/better/faster/simpler?
```
char[4] fourC(string s)
{
uint res;//Zero initialized, not 0xff initialized.
autocnt = min(s.length, 4),
p = cast(char[4]*)(&res);
(*p)[0..cnt] = s[0..cnt];
return *p;
}
```
I tri