Here's a bit of inspirational code @mmahoney :
library("stringr")
db = c("dan", "john", "kyle")
s = str_replace(string = "johnsmith", pattern = db, replacement = "")
i = which.min(nchar(s))
n = c(db[i], s[i])
Yielding
> n
[1] "john" "smith"
Hope it helps 