From Test-Scratch-Wiki

Deleting part of a 字串 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 函式积木 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

  • 变量s 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

Programming

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

定義 delete portion of (base) from (start) to (ending)
變數 [i v] 設為 [1]
變數 [result v] 設為 [] // starts blank
重複 ((start) - (1)) 次 
  變數 [result v] 設為 (字串組合 (result) 和 (字串中第 (i) 字\( (base) \)))
  變數 [i v] 改變 (1)
end
變數 [i v] 設為 ((ending) + (1))
重複 ((字串長度\( (base) \)) - (ending)) 次 
  變數 [result v] 設為 (字串組合 (result) 和 (字串中第 (i) 字\( (base) \)))
  變數 [i v] 改變 (1)
end

参见

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