Finding Differences Between Strings

Usage

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.

Description

Computes which characters differ between two strings.

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)
Class 'str_diff' atomic (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