Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Tell the truth and run." -- Yugoslav proverb


devel / comp.lang.smalltalk.dolphin / Re: string to integer?

SubjectAuthor
* string to integer?john c
`* Re: string to integer?vin...@gmail.com
 `* Re: string to integer?john c
  `- Re: string to integer?john.a...@gmail.com

1
string to integer?

<c2c36e42-776e-4f64-881f-f10d7809fd5an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=160&group=comp.lang.smalltalk.dolphin#160

  copy link   Newsgroups: comp.lang.smalltalk.dolphin
X-Received: by 2002:a37:2743:: with SMTP id n64mr15468376qkn.394.1635192051025;
Mon, 25 Oct 2021 13:00:51 -0700 (PDT)
X-Received: by 2002:a05:6808:19a8:: with SMTP id bj40mr13538366oib.37.1635192050671;
Mon, 25 Oct 2021 13:00:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Mon, 25 Oct 2021 13:00:50 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=24.2.133.13; posting-account=FxwEXgoAAADcSnrOjqy8Iwckyp5OTz8K
NNTP-Posting-Host: 24.2.133.13
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c2c36e42-776e-4f64-881f-f10d7809fd5an@googlegroups.com>
Subject: string to integer?
From: jndbusiness@gmail.com (john c)
Injection-Date: Mon, 25 Oct 2021 20:00:51 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 10
 by: john c - Mon, 25 Oct 2021 20:00 UTC

hi all,

i'm trying to convert a string to an integer. the string is '+7' (43, 55). so i thought Integer fromString: aString would be the answer. not so easy. it fails with an 'Invalid format for Integer' . not sure why it's an invalid format, but be that as it may, what are my options? just for grins, '-7' --> -7 works just fine, so what is it with '+'?

thanks in advance for help,

john

Re: string to integer?

<e9a99f09-958c-4140-8df9-601e9e7b2627n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=161&group=comp.lang.smalltalk.dolphin#161

  copy link   Newsgroups: comp.lang.smalltalk.dolphin
X-Received: by 2002:a05:620a:31aa:: with SMTP id bi42mr16420859qkb.76.1635206344909;
Mon, 25 Oct 2021 16:59:04 -0700 (PDT)
X-Received: by 2002:a05:6830:22c2:: with SMTP id q2mr15912722otc.84.1635206344546;
Mon, 25 Oct 2021 16:59:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Mon, 25 Oct 2021 16:59:04 -0700 (PDT)
In-Reply-To: <c2c36e42-776e-4f64-881f-f10d7809fd5an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=59.167.168.68; posting-account=5_w1_goAAAB1Y5P4_YBwBlB76XHrI38U
NNTP-Posting-Host: 59.167.168.68
References: <c2c36e42-776e-4f64-881f-f10d7809fd5an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e9a99f09-958c-4140-8df9-601e9e7b2627n@googlegroups.com>
Subject: Re: string to integer?
From: vinref@gmail.com (vin...@gmail.com)
Injection-Date: Mon, 25 Oct 2021 23:59:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 20
 by: vin...@gmail.com - Mon, 25 Oct 2021 23:59 UTC

On Tuesday, 26 October 2021 at 06:00:51 UTC+10, john c wrote:
> hi all,
>
> i'm trying to convert a string to an integer. the string is '+7' (43, 55).. so i thought Integer fromString: aString would be the answer. not so easy.. it fails with an 'Invalid format for Integer' . not sure why it's an invalid format, but be that as it may, what are my options? just for grins, '-7' --> -7 works just fine, so what is it with '+'?
>
> thanks in advance for help,
>
> john
Integer class>>#readFrom: only ever checks for the existence of negative sign to signify a negative number, not the positive sign to signify a positive number. I guess a number without a positive sign is always considered a positive number and the presence of the positive sign is seen as an error.

You will have to strip the positive sign (aString reject: [ :each | each = $+ ])

Vince

Re: string to integer?

<88ac5871-2b71-4a7d-a38f-b4c8ea7e0063n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=162&group=comp.lang.smalltalk.dolphin#162

  copy link   Newsgroups: comp.lang.smalltalk.dolphin
X-Received: by 2002:ac8:3d49:: with SMTP id u9mr21936687qtf.264.1635209898394;
Mon, 25 Oct 2021 17:58:18 -0700 (PDT)
X-Received: by 2002:a05:6808:1148:: with SMTP id u8mr14922072oiu.69.1635209898082;
Mon, 25 Oct 2021 17:58:18 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Mon, 25 Oct 2021 17:58:17 -0700 (PDT)
In-Reply-To: <e9a99f09-958c-4140-8df9-601e9e7b2627n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=24.2.133.13; posting-account=FxwEXgoAAADcSnrOjqy8Iwckyp5OTz8K
NNTP-Posting-Host: 24.2.133.13
References: <c2c36e42-776e-4f64-881f-f10d7809fd5an@googlegroups.com> <e9a99f09-958c-4140-8df9-601e9e7b2627n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <88ac5871-2b71-4a7d-a38f-b4c8ea7e0063n@googlegroups.com>
Subject: Re: string to integer?
From: jndbusiness@gmail.com (john c)
Injection-Date: Tue, 26 Oct 2021 00:58:18 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 31
 by: john c - Tue, 26 Oct 2021 00:58 UTC

On Monday, October 25, 2021 at 7:59:05 PM UTC-4, vin...@gmail.com wrote:
> On Tuesday, 26 October 2021 at 06:00:51 UTC+10, john c wrote:
> > hi all,
> >
> > i'm trying to convert a string to an integer. the string is '+7' (43, 55). so i thought Integer fromString: aString would be the answer. not so easy. it fails with an 'Invalid format for Integer' . not sure why it's an invalid format, but be that as it may, what are my options? just for grins, '-7' --> -7 works just fine, so what is it with '+'?
> >
> > thanks in advance for help,
> >
> > john
> Integer class>>#readFrom: only ever checks for the existence of negative sign to signify a negative number, not the positive sign to signify a positive number. I guess a number without a positive sign is always considered a positive number and the presence of the positive sign is seen as an error.
>
> You will have to strip the positive sign (aString reject: [ :each | each = $+ ])
>
> Vince
thanks vince,

i arrived at that same conclusion and i'm modifying as we speak. with that said, it strikes me that a valid format should be accepted rather than putting on every developer.

sorry, just ranting.

john

Re: string to integer?

<9b411832-40b3-43aa-9901-3627604d7380n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=163&group=comp.lang.smalltalk.dolphin#163

  copy link   Newsgroups: comp.lang.smalltalk.dolphin
X-Received: by 2002:ac8:5f91:: with SMTP id j17mr24814858qta.138.1635252154975;
Tue, 26 Oct 2021 05:42:34 -0700 (PDT)
X-Received: by 2002:a05:6830:1f27:: with SMTP id e7mr19300896oth.346.1635252154631;
Tue, 26 Oct 2021 05:42:34 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Tue, 26 Oct 2021 05:42:34 -0700 (PDT)
In-Reply-To: <88ac5871-2b71-4a7d-a38f-b4c8ea7e0063n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=85.203.71.185; posting-account=OQ6sIwoAAAC1iWrFEUhdmRsgEkeDOgOm
NNTP-Posting-Host: 85.203.71.185
References: <c2c36e42-776e-4f64-881f-f10d7809fd5an@googlegroups.com>
<e9a99f09-958c-4140-8df9-601e9e7b2627n@googlegroups.com> <88ac5871-2b71-4a7d-a38f-b4c8ea7e0063n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9b411832-40b3-43aa-9901-3627604d7380n@googlegroups.com>
Subject: Re: string to integer?
From: john.aspinall@gmail.com (john.a...@gmail.com)
Injection-Date: Tue, 26 Oct 2021 12:42:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 50
 by: john.a...@gmail.com - Tue, 26 Oct 2021 12:42 UTC

Hi John - the comment for Number class>>readFrom: states

"Any numbers in the stream are expected to obey Smalltalk syntax rather than any locale specific formatting, i.e. this is not intended for reading user input."

....so bearing this in mind the error is correct since +7 is not valid Smalltalk syntax.

I thought that the NumberToText class would handle your scenario since it's part of the MVP framework and thus potentially user-facing. However it also uses Number class>>readFrom: and so has the same problem (though it does at least have a #todo comment on the reverse conversion saying "...should use GetNumberFormat() to produce locale specific output").

On Tuesday, October 26, 2021 at 1:58:18 AM UTC+1, john c wrote:
> On Monday, October 25, 2021 at 7:59:05 PM UTC-4, vin...@gmail.com wrote:
> > On Tuesday, 26 October 2021 at 06:00:51 UTC+10, john c wrote:
> > > hi all,
> > >
> > > i'm trying to convert a string to an integer. the string is '+7' (43, 55). so i thought Integer fromString: aString would be the answer. not so easy. it fails with an 'Invalid format for Integer' . not sure why it's an invalid format, but be that as it may, what are my options? just for grins, '-7' --> -7 works just fine, so what is it with '+'?
> > >
> > > thanks in advance for help,
> > >
> > > john
> > Integer class>>#readFrom: only ever checks for the existence of negative sign to signify a negative number, not the positive sign to signify a positive number. I guess a number without a positive sign is always considered a positive number and the presence of the positive sign is seen as an error.
> >
> > You will have to strip the positive sign (aString reject: [ :each | each = $+ ])
> >
> > Vince
> thanks vince,
>
> i arrived at that same conclusion and i'm modifying as we speak. with that said, it strikes me that a valid format should be accepted rather than putting on every developer.
>
> sorry, just ranting.
>
> john

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor