Computes which characters differ between two strings.

str_diff(x, y)

Arguments

x

a single string

y

a single string

Value

an integer vector containing the index of all mis-matched characters in the first string.

Examples

# strings to compare x <- "once upon a time" y <- "once upon a time there was" z <- "once upon two times" # diff: x - y d <- str_diff(x, y) d
#> once upon a time #> ................---------- #> once upon a time there was
str(d)
#> 'str_diff' Named int(0) #> - attr(*, "names")= chr(0) #> - attr(*, "str")=List of 2 #> ..$ x: chr "once upon a time" #> ..$ y: chr "once upon a time there was"
# other comparisons str_diff(y, x)
#> once upon a time there was #> ................++++++++++ #> once upon a time
str_diff(x, x)
#> once upon a time #> ................ #> once upon a time
str_diff(x, z)
#> once upon a time #> ..........******--- #> once upon two times
str_diff(y, z)
#> once upon a time there was #> ..........*********+++++++ #> once upon two times