Deleting part of a string is the process by which a certain segment or portion of a string is removed, leaving the rest of the string behind. This tutorial describes how to delete the specified portion of a string. Scratch 2.0's "run without screen refresh" option for custom blocks allows the string portion to be removed at atomic speeds without taking up more than one frame of the video output. For this tutorial, assume the following:

  • The custom block used to delete part of the string takes three parameters
    • "base" — the body string by which a part will be deleted
    • "start" — the position of the first letter of the base to begin the deleting, which is included in the deletion
    • "ending" — the position of the last letter to be deleted in the sequence that is removed
  • Variables are used in the process of deleting the part
    • (result) — the final string with the specified parts removed from the original
    • (i) — used for grouping and iteration


The following custom block deletes a portion of the specified string:

define delete portion of (base) from (start) to (ending)
set [i v] to [1]
set [result v] to [] //starts blank
repeat ((start) - (1))
    set [result v] to (join (result) (letter (i) of (base)))
    change [i v] by (1)
set [i v] to ((ending) + (1))
repeat ((length of (base)) - (ending))
    set [result v] to (join (result) (letter (i) of (base)))
    change [i v] by (1)

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.