HP Forums
Usage of MID() - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Usage of MID() (/thread-18264.html)



Usage of MID() - matalog - 04-15-2022 09:41 PM

If I set up a string STR1:="123";

Then I use MID(STR1,9), it will return the last digit "3", even though it is the 3rd position of the string, I would thought it would have returned "" given that there is nothing in the 9th position.

Using PUREBASIC for example, I get nothing output to terminal.

MID("123",6) on the Prime, returns 3.

Is that normal?


RE: Usage of MID() - toml_12953 - 04-16-2022 12:18 PM

(04-15-2022 09:41 PM)matalog Wrote:  If I set up a string STR1:="123";

Then I use MID(STR1,9), it will return the last digit "3", even though it is the 3rd position of the string, I would thought it would have returned "" given that there is nothing in the 9th position.

Using PUREBASIC for example, I get nothing output to terminal.

MID("123",6) on the Prime, returns 3.

Is that normal?

I don't like it but that's the way it works on mine, too.


RE: Usage of MID() - matalog - 04-16-2022 01:30 PM

It doesn't work like that on the 50g, SUB(4,4,"123") doesn't return anything.

Casio CG50 StrMid("123",5,5) doesn't return anything.

I don't know of another language where MID will return something outside of the set range.


RE: Usage of MID() - Albert Chan - 04-16-2022 01:56 PM

(04-15-2022 09:41 PM)matalog Wrote:  MID("123",6) on the Prime, returns 3.

With lower-cased mid, bug is gone (at least on the emulator)

CAS> mid("123",6)      → ""


RE: Usage of MID() - matalog - 04-16-2022 03:30 PM

(04-16-2022 01:56 PM)Albert Chan Wrote:  
(04-15-2022 09:41 PM)matalog Wrote:  MID("123",6) on the Prime, returns 3.

With lower-cased mid, bug is gone (at least on the emulator)

CAS> mid("123",6)      → ""

And confirmed on a G2.

Is there any way to ensure the CAS version of MID will be used from any program?

That should be enough to all it a bug. There is no reason to have MID behave differently in CAS than Home.


RE: Usage of MID() - StephenG1CMZ - 04-16-2022 05:06 PM

This will work in PPL:
ST:="123";
CAS("mid(ST, 6) ");
It also works from CAS home screen - I haven't tried it within a CAS program.


RE: Usage of MID() - matalog - 04-16-2022 07:10 PM

(04-16-2022 05:06 PM)StephenG1CMZ Wrote:  This will work in PPL:
ST:="123";
CAS("mid(ST, 6) ");
It also works from CAS home screen - I haven't tried it within a CAS program.

That is the second time this week I have seen a suggestion to use CAS( something) as a work around.

What does that use of CAS do, as it usually contains more quotations that you would usually see?

Is it documented in the manual?


RE: Usage of MID() - StephenG1CMZ - 04-16-2022 07:35 PM

The short answer:
The expression is parsed by CAS and more information is available in CAS help.
I have seen CAS(string) used, and also CAS.function (e.g. CAS.mid(...) ).
It's an alternative to just using mid within a CAS program.
Note that MID is normally the PPL version and mid the CAS version, though their are exceptions.

I am sure the experts can explain it much better.


RE: Usage of MID() - jte - 01-12-2023 01:54 AM

matalog,

Thanks for posting. And thanks to the others for their comments and confirmation. I filed a bug report for this on the bug tracking site I’ve set up. … and the bug got fixed! Big Grin

(If anyone reading this would like an account on the bug tracker I’ve set up to help organize matters, just let me know by PM.)


RE: Usage of MID() - jte - 01-19-2023 08:37 AM

Unfortunately, the fix has broken at least one program; see https://www.hpmuseum.org/forum/thread-11523-post-168494.html#pid168494. Luckly, there, a quick patch to the game’s source code (for loading “sayings”) seems to do the trick. (E.g., changing “DIM(str)==1” to “DIM(str)<2”.)