@jiminp/tooltool
    Preparing search index...

    Function getRowCol

    • Get the row and column position of a character in a string.

      Parameters

      • s: string

        The target string to search within.

      • ind: number

        The zero-based index of the character. Must satisfy 0 <= ind && ind <= s.length. When ind === s.length, returns the position after the last character.

      • Optionalpretty: false

        If true, returns a human-readable string "row:col" (1-based). If false or omitted, returns a tuple [row, col] (0-based).

      Returns RowCol

      • When pretty is false: A tuple [row, col] where both values are 0-based.
      • When pretty is true: A string in the format "row:col" where both values are 1-based.

      If ind is negative or greater than s.length.

      • Line breaks are determined by the newline character (\n).
      • Carriage returns (\r) are treated as regular characters, not line breaks.
      const text = "hello\nworld";

      getRowCol(text, 0); // [0, 0] - 'h' at row 0, col 0
      getRowCol(text, 5); // [0, 5] - '\n' at row 0, col 5
      getRowCol(text, 6); // [1, 0] - 'w' at row 1, col 0
      getRowCol(text, 11); // [1, 5] - position after 'd'

      getRowCol(text, 6, true); // "2:1" - 'w' at row 2, col 1 (1-based)
    • Get the row and column position of a character in a string.

      Parameters

      • s: string

        The target string to search within.

      • ind: number

        The zero-based index of the character. Must satisfy 0 <= ind && ind <= s.length. When ind === s.length, returns the position after the last character.

      • pretty: true

        If true, returns a human-readable string "row:col" (1-based). If false or omitted, returns a tuple [row, col] (0-based).

      Returns `${number}:${number}`

      • When pretty is false: A tuple [row, col] where both values are 0-based.
      • When pretty is true: A string in the format "row:col" where both values are 1-based.

      If ind is negative or greater than s.length.

      • Line breaks are determined by the newline character (\n).
      • Carriage returns (\r) are treated as regular characters, not line breaks.
      const text = "hello\nworld";

      getRowCol(text, 0); // [0, 0] - 'h' at row 0, col 0
      getRowCol(text, 5); // [0, 5] - '\n' at row 0, col 5
      getRowCol(text, 6); // [1, 0] - 'w' at row 1, col 0
      getRowCol(text, 11); // [1, 5] - position after 'd'

      getRowCol(text, 6, true); // "2:1" - 'w' at row 2, col 1 (1-based)