Skip to contents

Compare strings semantically or exactly

Usage

string_identical(x, y, mode = c("semantic", "exact"))

Arguments

x

A character vector

y

Another character vector to compare to x

mode

Either `"semantic"` to compare text after normalizing non-byte strings to UTF-8, or `"exact"` to additionally require matching encoding. Strings marked as `"bytes"` are always compared exactly.

Value

TRUE if strings are identical under the selected comparison mode

See also

identical

Examples

x <- "fa\xE7ile"
Encoding(x) <- "latin1"
y <- iconv(x, "latin1", "UTF-8")
identical(x, y) # TRUE
#> [1] TRUE
string_identical(x, y) # TRUE
#> [1] TRUE
string_identical(x, y, mode = "exact") # FALSE
#> [1] FALSE