Contains v0.1.0

Source
Reports whether a substring occurs anywhere in the string.

Package: Text

Signature

func Contains(self, needle: String) -> bool;

Parameters

NameTypeDescription
needleStringThe bytes to search for.

Returns

true when the bytes of needle occur anywhere in the string. The empty needle is contained in every string, and a needle longer than the string is contained in none.

This is IndexOf with the offset thrown away, and it costs the same — ask IndexOf instead when the position matters.

Example

import Text::String;

func Main() -> int {
    var text = String::From("Hello, Rux!");
    var needle = String::From("Rux");

    text.Contains(needle); // true

    needle.Free();
    text.Free();
    return 0;
}

See also

  • String — the string type
  • IndexOf — the same search, reporting where the match is
  • StartsWith — the cheaper test when the match has to be at the front