How to loop through characters of a string in D language?

BoQsc vaidas.boqsc at gmail.com
Wed Dec 8 13:17:13 UTC 2021


On Wednesday, 8 December 2021 at 12:49:39 UTC, Adam D Ruppe wrote:
> On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
>> The string example to loop/iterate:
>
> foreach(ch; a) {
>
> }
>
> does the individual chars of the string you can also
>
> foreach(dchar ch; a) {
>
> }
>
> to decode the utf 8

Thanks Adam.

This is how it would look implemented.

```
import std.stdio;

void main()
{
     string a = "abc;def;ab";
	string b;
	
	foreach(ch; a) {
		if (ch != ';'){
			b ~= ch;
		}
	
		writeln(ch);
	}
	
     writeln(b);
}
```


More information about the Digitalmars-d-learn mailing list