Maybe not the most simple answer, but this will work:
paste(sort(unlist(strsplit(s, ""))), collapse = "")
Or modify the strReverse
function that is defined in the help page for ?strsplit
to suit our needs. We'll call it strSort:
strSort <- function(x)
sapply(lapply(strsplit(x, NULL), sort), paste, collapse="")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…