#### string to integer?

```Hi All,

How do I assign a string that looks like an integer
into an interger?

\$str = "601"  -- > \$int = 601

Many thanks,
-T
``` 0  ToddAndMargo
8/6/2018 8:58:43 PM perl.perl6.users  1149 articles. 0 followers. 1 Replies 96 Views Similar Articles

[PageSpeed] 3

```On 08/06/2018 01:58 PM, ToddAndMargo wrote:
> Hi All,
>=20
> How do I assign a string that looks like an integer
> into an interger?
>=20
> \$str =3D "601"=C2=A0 -- > \$int =3D 601
>=20
>=20
> Many thanks,
> -T

My notes on String to Integer and Integer to String:

Perl 6: convert String to Integer and Integer to String:

String to Integer:
\$ p6 'my Str \$x =3D "122333"; my Int \$y =3D \$x.Int; say \$y;'
122333

\$ p6 'my Int \$x; my Str \$y =3D "5"; \$x =3D "\$y" + 0; say "\$x";'
5

Integer to String:
\$ p6 'my Int \$x =3D 122333; my Str \$y =3D \$x.Str; say \$y;'
122333

\$ p6 'my Str \$x; my Int \$y =3D 9; \$x =3D "\$y"; say "\$x";'
9

\$ p6 'my Str \$x =3D "1\n22\n333\n"; my Int @y; @y =3D ( split "\n", \$=
x,=20
:skip-empty )>>.Int; for @y -> Int \$i {say \$i;}'
1
22
333

\$ p6 'my Str \$x =3D "1\n22\n333\n"; my Int @y; for ( split "\n", \$x, =

:skip-empty )>>.Int -> \$i {say \$i;}'
1
22
333

"dd":
\$ p6 'my Str \$x =3D "5"; my Int \$y =3D dd +\$x; say \$y'
5
(Int)

\$ p6 'my Int \$y =3D 7; my Str \$x =3D dd ~\$y; say \$x'
"7"
(Str)
``` 0  ToddAndMargo
8/7/2018 9:11:59 AM