How to loop through characters of a string in D language?
Matheus
matheus at gmail.com
Fri Dec 10 13:22:58 UTC 2021
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
> ...
> The character I want to skip: `;`
My C way of thinking while using D:
import std;
string stripsemicolons(string input){
char[] s = input.dup;
int j=0;
for(int i=0;i<input.length;++i){
if(s[i] == ';'){ continue; }
s[j++] = s[i];
}
s.length = j;
return s.idup;
}
void main(){
string s = ";testing;this;thing!;";
writeln(s);
writeln(s.stripsemicolons);
return;
}
Matheus.
More information about the Digitalmars-d-learn
mailing list