From Test-Scratch-Wiki

Clock.png This article or section contains information about a feature from a future version of Scratch that is unreleased and is subject to change. Some Scratch Blocks may not display correctly on this page.
Document stub.png This article is a stub. It may be broken, incomplete, unfinished, or have missing parts/sections. If you can help expand this article, please help! There might be suggestions on its talk page.

The () Contains () 积木 is an 运算类积木 and a 菱形积木. The block checks if the first parameter's text contains the second parameter's text —if it does, the block reports true; otherwise, it reports false, and this is case-insensitive. This block will be released with Scratch 3.0.[1]


Checking whether input contains a certain 字串 - useful for soft-checking as the actual input may not be exactly identical:

當 @greenflag 被點擊
造型換成 [bunny v]
詢問 [What's this animal?] 並等待
如果 <清單 (詢問的答案) 包含 [bunny] ?> 那麼 
  說出 [Correct!]
  說出 [Nope!]
end //  contains is used instead of = because the user might say "it's a bunny"


Main article: List of Block Workarounds
定義 (string1) contains (string2)
變數 [i v] 設為 [0]
變數 [j v] 設為 [1]
重複 (字串長度\( (string1) \)) 次 
  變數 [i v] 改變 (1)
  如果 <(字串中第 (i) 字\( (string1) \)) = (字串中第 (j) 字\( (string2) \))> 那麼 
    變數 [j v] 設為 [1]
    重複直到 <<<(字串中第 ((i) + (j)) 字\( (string1) \)) = (字串中第 (j) 字\( (string2) \))> 不成立> 或 <(j) > (字串長度\( (string2) \))>> 
      變數 [j v] 改變 (1)
    如果 <(j) > (字串長度\( (string2) \))> 那麼 
      變數 [result v] 設為 [true]
      停止 [這個程式 v]


  1. thisandagain. (10/8/2017). 'Blocks - implement "[string] contains [string]" reporter.[title]'
Cookies help us deliver our services. By using our services, you agree to our use of cookies.