package stringx

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Stringx.LevenshteinSource

Sourceval distance : string -> string -> int

distance s t computes the Levenshtein (edit) distance between two UTF-8 encoded strings.

The Levenshtein distance is the minimum number of single-character edits (insertions, deletions, or substitutions) required to transform one string into another.

This implementation is Unicode-aware and correctly handles multibyte characters such as Japanese, Chinese, emoji, and accented letters.

Examples:

  • distance "kitten" "sitting" returns 3
  • distance "こんにちは" "こんばんは" returns 2
  • distance "🍎" "🍏" returns 1

Malformed UTF-8 sequences are replaced with '?' during decoding.

  • parameter s

    The first UTF-8 encoded string

  • parameter t

    The second UTF-8 encoded string

  • returns

    The edit distance between s and t

OCaml

Innovation. Community. Security.