The function search for the longest common prefix between multiple strings.
comsub(data, sep = "")
data | A vector of strings |
---|---|
sep | A character which is used to separate elements; default ("") is used to compare single characters; other useful alternatives are "/" (or "\\\\" in Windows) to find the longest common directory, or " " to compare words instead of characters. |
A character with the longest common initial substring
Modified from a suggestion taken from stackoverflow.
strings <- c("/home/user/git/sen2r", "/home/user/git_data/sen2r/ex/vrt/01_translate/") comsub(strings)#> [1] "/home/user/git"comsub(strings, sep="/")#> [1] "/home/user/"