Concatenates int
Rikki Cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 10 05:22:58 PDT 2014
On 11/07/2014 12:11 a.m., Sean Campbell wrote:
> i have the ints 4, 7, 0 and 1 how can i Concatenate them into four
> thousand seven hundred and one.
If we talking at compile time definition:
int myint = 4_7_0_1;
Would work.
However I'll assume its at runtime you really want this.
I.e. converting a string to an integer.
int myint = to!int("4" ~ "7" ~ "0" ~ "1");
Now they are not strings, and the positions of 10^ doesn't change then:
int myint = (1000 * 4) + (100 * 7) + 1;
More information about the Digitalmars-d-learn
mailing list