Skip to main content
Log in

Mojo function

ord

ord(s: StringSlice[origin]) -> 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[origin]): The input string, which must contain only a single- character.

Returns:

An integer representing the code point of the given character.