Skip to content

MakeCode, substr, the substring copy to the end of the string does not work  #5436

Open
microsoft/pxt
#10559
@JanTadeuszEkiel

Description

@JanTadeuszEkiel

Describe the bug
I have a prpblem with using MakeCode's function to cut text from a designated character number to the end of a character string.

The help document (https://github.com/Microsoft/pxt/blob/master/common-docs/reference/text/substr.md) states:
"
If you want to have the substring copy to the end of the first string, you just use the starting position without any length number. This will copy all of the first string beginning at position 6. The substring will say "there!!!" in this case.

let there = "Hello there!!!".substr(6);
"
Unfortunately, when I remove the number that specifies the last character from the string I want to copy, the browser inserts a "0" (zero) in that place. I can remove the end number of the copied string in the Python code preview but this change to the end still doesn't work. I tested the error on MS Windows with Chrome browser and on Raspberry Pi 4 with Chrome browser.

To Reproduce

  1. open the makecode editor for micro:bit
  2. add a variable named "test"
  3. add a "set" fucction for the variable test to the "ons start" block and from the "Text" menu, drop a STRING "" into it
  4. write the string "Hello Programmer!" into it.
  5. create a new variable Test2
  6. insert the substring (substring) fukition from the Text menu into test2
  7. in "sumstring of" insert the variable "test"
  8. in "from" insert the value 6 to cut all the text to the end of the string, which contains the word "Programmer"
  9. from the field "of lenght" remove the value "0" (zero) and leave this field empty
  10. click the mouse anywhere outside the "of lenght" field and the browser will automatically fill it back in with the value "0) (zero)

Expected behavior
If you want to have the substring copy to the end of the first string, you just use the starting position without any length number. This will copy all of the first string beginning at position 6. The substring will say "there!!!" in this case.

let there = "Hello there!!!".substr(6);

micro:bit version (please complete the following information):

You can find this information in the lower right hand corner of the back of micro:bit (the side that says BBC micro:bit).

  • Which version of the micro:bit is this relevant to v1.5 and v2.0

Desktop (please complete the following information):

  • OS: MS Windows i Raspberry Pi 4 (Debian)
  • Browser Chrome
  • Version 120

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions