fork download
  1. strdiff <- function(src, dest)
  2. {
  3. x <- unlist(strsplit(attr(adist(src, dest, counts = TRUE), "trafos"), ""))
  4. n <- length(x)
  5. spos <- 1:(n + 1) - c(0, cumsum(x == "I"))
  6. dpos <- 1:(n + 1) - c(0, cumsum(x == "D"))
  7.  
  8. cat(src, "->", dest, "\n")
  9. for (i in 1:n) {
  10. if (x[i] == "D" | x[i] == "S") {
  11. cat(sprintf("-%d:%s\n", i, substr(src, spos[i], spos[i])))
  12. }
  13. if (x[i] == "I" | x[i] == "S") {
  14. cat(sprintf("+%d:%s\n", i, substr(dest, dpos[i], dpos[i])))
  15. }
  16. }
  17. cat("\n")
  18. }
  19.  
  20. strdiff("abcdef", "abdef")
  21. strdiff("abdef", "bcdef")
  22. strdiff("bcdef", "abcdef")
Success #stdin #stdout 0.21s 38928KB
stdin
Standard input is empty
stdout
abcdef -> abdef 
-3:c

abdef -> bcdef 
-1:a
+3:c

bcdef -> abcdef 
+1:a