我有德语文本,我想用ae,oe,ue等替换所有变音符号(ä,Ä,ü,Ü,ö,Ö).
我可以单独完成(通过将每个替换保存到一个新文件中):
gsub(pattern = '[ä]', replacement = "ae",text)
gsub(pattern = '[ü]', replacement = "ue",text)
gsub(pattern = '[ö]', replacement = "oe",text)
但是我可以用一个命令来做(包括用Ae,Oe和Ue代替大写字母等)吗?
我可以用正则表达式做到吗?
最佳答案 你可以试试
# install.packages("stringi) # uncomment & run if needed
str <- c("äöü", "ÄÖÜ")
stringi::stri_replace_all_fixed(
str,
c("ä", "ö", "ü", "Ä", "Ö", "Ü"),
c("ae", "oe", "ue", "Ae", "Oe", "Ue"),
vectorize_all = FALSE
)
# [1] "aeoeue" "AeOeUe"