StartsWith v0.1.0

Source
Reports whether the string opens with a prefix.

Package: Text

Signature

func StartsWith(self, prefix: String) -> bool;

Parameters

NameTypeDescription
prefixStringThe bytes to look for at the front.

Returns

true when the string's first bytes are the bytes of prefix. Every string starts with the empty one, and none starts with a prefix longer than itself.

The comparison is byte for byte and case-sensitive, on the same terms as Equals.

Example

import Text::String;

func Main() -> int {
    var path = String::From("/usr/local/bin");
    var root = String::From("/usr");

    path.StartsWith(root);          // true
    path.StartsWith(String::New()); // true -- the empty prefix always matches

    root.Free();
    path.Free();
    return 0;
}

See also

  • String — the string type
  • EndsWith — the same test at the other end
  • IndexOf — find the bytes anywhere, not only at the front
  • Equals — compare the whole string