Google表格功能可将字符串转换为可读的网址

问题描述 投票:1回答:2

我搜索google-sheets函数将字符串转换为可读的URL

string:“这是德语中的一个字符串,带有尖锐的ß和烦人的愚蠢的变音符号”

url:“这是一个德国人用尖锐的ss-and-angry-bloeden-umlauten”

  • Ü到你
  • 给你
  • 然后
  • ü到了
  • 给你
  • ß到ss
  • “空间” -
url google-sheets
2个回答
1
投票
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(A2), 
 "ä", "ae"), 
 "ü", "ue"),
 "ö", "oe"),
 "ß", "ss"), 
 " ", "-")

0


对于数组采取这个:

=ARRAYFORMULA(IFERROR(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(A2:A), 
 "ä", "ae"), 
 "ü", "ue"),
 "ö", "oe"),
 "ß", "ss"), 
 " ", "-")))

1
投票

创建此自定义功能

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(将任何剩余的大写字母缩小为小写)的组合。


enter image description here


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();
}
© www.soinside.com 2019 - 2024. All rights reserved.