Hi all,
I'm parsing some text which contains numbers like "8.324" and I would like to convert it to integer. The problem is that asNumber and asInteger don't make the trick because of the dot ("."), which is there to indicate thousands, not decimal values. Which is the proper message to send? Cheers, Offray |
Do you have more details? Such as, do you have values with more than one dot ? (e.g. 1.436.782) Do you have values with no dot? -----------------
Benoit St-Jean Yahoo! Messenger: bstjean Twitter: @BenLeChialeux Pinterest: benoitstjean IRC: lamneth Blogue: endormitoire.wordpress.com "A standpoint is an intellectual horizon of radius zero". (A. Einstein) From: Offray Vladimir Luna Cárdenas <[hidden email]> To: Any question about pharo is welcome <[hidden email]> Sent: Saturday, April 4, 2015 7:17 PM Subject: [Pharo-users] Converting a string containing dots to integer Hi all, I'm parsing some text which contains numbers like "8.324" and I would like to convert it to integer. The problem is that asNumber and asInteger don't make the trick because of the dot ("."), which is there to indicate thousands, not decimal values. Which is the proper message to send? Cheers, Offray |
In reply to this post by Offray
This might do the trick: (Number readFrom: ('8.524.757' copyReplaceAll: '.' with: '')) asInteger or even nicer (and simpler) ('8.524.757' reject: [:char | char == $.]) asInteger -----------------
Benoit St-Jean Yahoo! Messenger: bstjean Twitter: @BenLeChialeux Pinterest: benoitstjean IRC: lamneth Blogue: endormitoire.wordpress.com "A standpoint is an intellectual horizon of radius zero". (A. Einstein) From: Offray Vladimir Luna Cárdenas <[hidden email]> To: Any question about pharo is welcome <[hidden email]> Sent: Saturday, April 4, 2015 7:17 PM Subject: [Pharo-users] Converting a string containing dots to integer Hi all, I'm parsing some text which contains numbers like "8.324" and I would like to convert it to integer. The problem is that asNumber and asInteger don't make the trick because of the dot ("."), which is there to indicate thousands, not decimal values. Which is the proper message to send? Cheers, Offray |
In reply to this post by Pharo Smalltalk Users mailing list
If it's for the thousand you can use that: To find this kind of methods you can use the finder (world -> Tools). You select "example" and you search for things like :(myStringNumber copyWithoutAll: '.') asNumber '1.234'.'.'.'1234' -- Cheers Cyril FerlicotOn 5 April 2015 at 01:43, Benoit St-Jean via Pharo-users <[hidden email]> wrote:
|
Thanks a lot it works like a charm!
Cheers, Offray El 04/04/15 a las 19:13, Cyril Ferlicot escribió: > If it's for the thousand you can use that: > > (myStringNumber copyWithoutAll: '.') asNumber > > To find this kind of methods you can use the finder (world -> Tools). You select > "example" and you search for things like : > > '1.234'.'.'.'1234' > > and that will give you: > '1.234' copyWithoutAll: '.' first -> '1234' > > -- > Cheers > Cyril Ferlicot > > > On 5 April 2015 at 01:43, Benoit St-Jean via Pharo-users > <[hidden email] <mailto:[hidden email]>> wrote: > > > > ---------- Forwarded message ---------- > From: Benoit St-Jean <[hidden email] <mailto:[hidden email]>> > To: Any question about pharo is welcome <[hidden email] > <mailto:[hidden email]>> > Cc: > Date: Sat, 4 Apr 2015 23:40:01 +0000 (UTC) > Subject: Re: [Pharo-users] Converting a string containing dots to integer > Do you have more details? > > Such as, do you have values with more than one dot ? (e.g. 1.436.782) > Do you have values with no dot? > ----------------- > Benoit St-Jean > Yahoo! Messenger: bstjean > Twitter: @BenLeChialeux > Pinterest: benoitstjean > IRC: lamneth > > Blogue: endormitoire.wordpress.com <http://endormitoire.wordpress.com> > > "A standpoint is an intellectual horizon of radius zero". (A. Einstein) > > -------------------------------------------------------------------------------- > *From:* Offray Vladimir Luna Cárdenas <[hidden email] > <mailto:[hidden email]>> > *To:* Any question about pharo is welcome <[hidden email] > <mailto:[hidden email]>> > *Sent:* Saturday, April 4, 2015 7:17 PM > *Subject:* [Pharo-users] Converting a string containing dots to integer > > Hi all, > > I'm parsing some text which contains numbers like "8.324" and I would > like to convert it to integer. The problem is that asNumber and > asInteger don't make the trick because of the dot ("."), which is there > to indicate thousands, not decimal values. Which is the proper message > to send? > > Cheers, > > Offray > > > > > > |
Free forum by Nabble | Edit this page |