How to remove all characters from a string, except the integers?
forkit
forkit at gmail.com
Thu Mar 3 20:23:14 UTC 2022
On Thursday, 3 March 2022 at 19:28:36 UTC, matheus wrote:
>
> I'm a simple man who uses D with the old C mentality:
>
> import std.stdio;
>
> void main(){
> string s, str = "4A0B1de!2C9~6";
> foreach(i;str){
> if(i < '0' || i > '9'){ continue; }
> s ~= i;
> }
> writeln("Result: ", s);
> }
>
> Result: 401296
>
> Matheus.
mmm..but we no longer live in simple times ;-)
(i.e. unicode)
More information about the Digitalmars-d-learn
mailing list