我搜索google-sheets函数将字符串转换为可读的URL
string:“这是德语中的一个字符串,带有尖锐的ß和烦人的愚蠢的变音符号”
url:“这是一个德国人用尖锐的ss-and-angry-bloeden-umlauten”
创建此自定义功能
function multipass(text, ChangeFrom, ChangeTo) {
ChangeFrom = ChangeFrom.map (String);
var re = new RegExp(ChangeFrom.join('|'), 'g');
return text.replace(re, function (match) {return
ChangeTo[ChangeFrom.indexOf(match)];});
}
来自WebApps Multiple substitutions in a single text;由安斯特拉瑟的诺曼提供。
我的最终答案是:
=lower(multipass(B1,D2:D9,E2:E9))
是multipass
(进行多次转换)和lower
(将任何剩余的大写字母缩小为小写)的组合。
REVISION-查找和替换函数中的值
function fandr(text) {
// add key:value pairs to the "find_replace" variable
var find_replace = {
'Ä': 'ae',
'Ü': 'ue',
'Ö': 'oe',
'ä': 'ae',
'ü': 'ue',
'ö': 'oe',
'ß': 'ss',
' ': '-'
};
// loop through the keys and replace with the value
Object.keys(find_replace).map(function(find) {
var replace = find_replace[find];
// Logger.log("DEBUG: find key: "+find+", replace value: "+replace);//DEBUG
// note the "g" - this is to replace all the matches for the given key/value pair
text = text.replace(find, replace, "g");
//Logger.log("DEBUG: modified text = "+text);//DEBUG
});
//Logger.log("DEBUG: Final modified text = "+text.toLowerCase());//DEBUG
return text.toLowerCase();
}