How to remove all characters from a string, except the integers?
matheus
matheus at gmail.com
Thu Mar 3 19:28:36 UTC 2022
On Thursday, 3 March 2022 at 12:14:13 UTC, BoQsc wrote:
> I've looked around and it seems using regex is the only closest
> solution.
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.
More information about the Digitalmars-d-learn
mailing list