txt: ## contains.md
  contains
  
  Combined from primary sources listed below.
  
  # [In Str](#___top "go to top of document")[§](#(Str)_method_contains "direct link")
  
  See primary documentation
  [in context](/type/Str#method_contains)
  for **method contains**.
  
  ```raku
  multi method contains(Str:D: Cool:D $needle, :i(:$ignorecase), :m(:$ignoremark) --> Bool:D)
  multi method contains(Str:D: Str:D $needle, :i(:$ignorecase), :m(:$ignoremark) --> Bool:D)
  multi method contains(Str:D: Regex:D $needle --> Bool:D)
  multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos, :i(:$ignorecase), :m(:$ignoremark) --> Bool:D)
  multi method contains(Str:D: Str:D $needle, Int:D $pos, :i(:$ignorecase), :m(:$ignoremark) --> Bool:D)
  multi method contains(Str:D: Regex:D $needle, Int:D $pos --> Bool:D)
  multi method contains(Str:D: Regex:D $needle, Cool:D $pos --> Bool:D)
  ```
  
  Given a `Str` invocant (known as the *haystack*) and a first argument (known as the `$needle`), it searches for the `$needle` in the *haystack* from the beginning of the string and returns `True` if `$needle` is found. If the optional parameter `$pos` is provided, then `contains` will search the *haystack* starting from `$pos` characters into the string.
  
  ```raku
  say "Hello, World".contains('Hello');      # OUTPUT: «True␤»
  say "Hello, World".contains('hello');      # OUTPUT: «False␤»
  say "Hello, World".contains('Hello', 1);   # OUTPUT: «False␤»
  say "Hello, World".contains(',');          # OUTPUT: «True␤»
  say "Hello, World".contains(',', 3);       # OUTPUT: «True␤»
  say "Hello, World".contains(',', 10);      # OUTPUT: «False␤»
  ```
  
  In the first case, `contains` searches for the `'Hello'` string on the invocant right from the start of the invocant string and returns `True`. In the third case, the `'Hello'` string is not found since we have started looking from the second position (index 1) in `'Hello, World'`.
  
  Since Rakudo version 2020.02, the `$needle` can also be a [`Regex`](/type/Regex) in which case the `contains` method quickly returns whether the regex matches the string at least once. No [`Match`](/type/Match) objects are created, so this is relatively fast.
  
  ```raku
  say 'Hello, World'.contains(/\w <?before ','>/);    # OUTPUT: «True␤»
  say 'Hello, World'.contains(/\w <?before ','>/, 5); # OUTPUT: «False␤»
  ```
  
  Since Rakudo version 2020.02, if the optional named parameter `:ignorecase`, or `:i`, is specified, the search for `$needle` ignores the distinction between uppercase, lowercase, and titlecase letters.
  
  ```raku
  say "Hello, World".contains("world");              # OUTPUT: «False␤»
  say "Hello, World".contains("world", :ignorecase); # OUTPUT: «True␤»
  ```
  
  Since Rakudo version 2020.02, if the optional named parameter `:ignoremark`, or `:m`, is specified, the search for `$needle` only considers base characters, and ignores additional marks such as combining accents.
  
  ```raku
  say "abc".contains("ä");               # OUTPUT: «False␤»
  say "abc".contains("ä", :ignoremark);  # OUTPUT: «True␤»
  ```
  
  Note that because of how a [`List`](/type/List) or [`Array`](/type/Array) is [coerced](/type/List#method_Str) into a `Str`, the results may sometimes be surprising.
  
  ```raku
  say <Hello, World>.contains('Hello');    # OUTPUT: «True␤»
  say <Hello, World>.contains('Hello', 0); # OUTPUT: «True␤»
  say <Hello, World>.contains('Hello', 1); # OUTPUT: «False␤»
  ```
  
  See [traps](/language/traps#Lists_become_strings,_so_beware_.contains()).
  
  # [In Cool](#___top "go to top of document")[§](#(Cool)_method_contains "direct link")
  
  See primary documentation
  [in context](/type/Cool#method_contains)
  for **method contains**.
  
  ```raku
  method contains(Cool:D: |c)
  ```
  
  Coerces the invocant to a [`Str`](/type/Str), and calls [`Str.contains`](/type/Str#method_contains) on it. Please refer to that version of the method for arguments and general syntax.
  
  ```raku
  say 123.contains("2")# OUTPUT: «True␤»
  ```
  
  Since [`Int`](/type/Int) is a subclass of `Cool`, `123` is coerced to a [`Str`](/type/Str) and then `contains` is called on it.
  
  ```raku
  say (1,1, * + * … * > 250).contains(233)# OUTPUT: «True␤»
  ```
  
  [`Seq`](/type/Seq)s are also subclasses of `Cool`, and they are stringified to a comma-separated form. In this case we are also using an [`Int`](/type/Int), which is going to be stringified also; `"233"` is included in that sequence, so it returns `True`. Please note that this sequence is not lazy; the stringification of lazy sequences does not include each and every one of their components for obvious reasons.
  