IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0b1
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

ord

ord(s: StringSlice) -> Int

Returns an integer that represents the codepoint of a single-character string.

Given a string containing a single character Codepoint, return an integer representing the codepoint of that character. For example, ord("a") returns the integer 97. This is the inverse of the chr() function.

This function is in the prelude, so you don't need to import it.

Args:

  • s (StringSlice): The input string, which must contain only a single- character.

Returns:

Int: An integer representing the code point of the given character.