How to loop through characters of a string in D language?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Sun Dec 12 09:03:27 UTC 2021
On Sunday, 12 December 2021 at 08:58:29 UTC, Ola Fosheim Grøstad
wrote:
> this(string s)@trusted{
> begin = s.ptr;
> end = s.ptr + s.length;
> }
> }
Bug, it fails if the string ends or starts with ';'.
Fix:
```
this(string s)@trusted{
begin = s.ptr;
end = s.ptr + s.length;
while(begin!=end && *begin==stripchar) begin++;
while(begin!=end && *(end-1)==stripchar) end--;
}
```
More information about the Digitalmars-d-learn
mailing list