Convering strings containing number
Salih Dincer
salihdb at hotmail.com
Wed Jun 15 04:26:44 UTC 2022
Hi,
I've been interested in conversion possibilities for a while. I
tried to convert a string containing numbers but with no success
in single digits. The only solution I found is to subtract 48
from the result:
```d
import std;
void main()
{
string str = "abc123";
str[3..$].to!int.writeln; // 123
auto bar = str[3].to!int;
assert(bar == 49); // 49 is value for ASCII.
writeln(bar - 48); // 1
}
```
More information about the Digitalmars-d-learn
mailing list