to delete the '\0' characters
Paul Backus
snarwin at gmail.com
Fri Sep 23 22:17:51 UTC 2022
On Friday, 23 September 2022 at 18:37:59 UTC, Salih Dincer wrote:
> On Thursday, 22 September 2022 at 10:53:32 UTC, Salih Dincer
> wrote:
>> Is there a more accurate way to delete **the '\0' characters
>> at the end of the string?**
>
> * character**S**
> * at the **END**
> * of the **STRING**
Apologies for the confusion. You can use [`stripRight`][1] for
this:
```d
import std.string: stripRight;
import std.stdio: writeln;
void main()
{
string[] samples = [
"the one\0", "the two\0\0", "the three\0\0\0", "the
four\0\0\0\0",
"the five\0\0\0\0\0", "the six\0\0\0\0\0\0",
"the seven\0\0\0\0\0\0\0", "the eight\0\0\0\0\0\0\0\0"
];
foreach (s; samples) {
writeln(s.stripRight("\0"));
}
}
```
[1]: https://phobos.dpldocs.info/std.string.stripRight.2.html
More information about the Digitalmars-d-learn
mailing list