From Test-Scratch-Wiki
![]() |
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. |
![]() |
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) end 如果 <(j) > (字串長度\( (string2) \))> 那麼 變數 [result v] 設為 [true] 停止 [這個程式 v] end end end
参考
- ↑ thisandagain. (10/8/2017). 'Blocks - implement "[string] contains [string]" reporter.[title]' https://github.com/LLK/scratch-gui/issues/601
() + ()
• () - () • () * () • () / () • 随机取数 () 到 () • () < () • () = () • () > () • () 且 () • () 或 () • () 不成立 • 字串组合 () 和 () • 字串中第 () 字 () • 字串长度 () • ) 除 () 的馀数 • 四舍五入数值 () • () 数值 ()更多积木… |