This article is about the operators block. For the lists block, see () Contains ()? (List block).
() Contains ()
X contains y 3.0.png
Category Operators
Type Boolean
Introduced in 3.0

The () Contains () block is an Operators block and a Boolean block. 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.

Example Use

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

when gf clicked
switch costume to [bunny v]
ask [What's this animal?] and wait
if <(answer) contains [bunny] :: operators> then // the contains block is used instead of equal to because the user might say "it's a bunny"
  say [Correct!]
  say [Nope!]


Main article: List of Block Workarounds
define (string1) contains (string2)::custom
set [i v] to [0]
set [j v] to [1]
repeat (length of (string1))
  change [i v] by (1)
  if <(letter (i) of (string1)) = (letter (j) of (string2))> then
    set [j v] to [1]
    repeat until <<not <(letter ((i) + (j)) of (string1)) = (letter (j) of (string2))>> or <(j) > (length of (string2))>>
      change [j v] by (1)
    if <(j) > (length of (string2))> then
      set [result v] to [true]
      stop [this script v]