简体   繁体   English

Google Apps脚本中的localeCompare可以使用哪些选项?

[英]What options are available to localeCompare in Google Apps Script?

Anybody know what options are available? 有人知道可用的选项吗?

Chrome console allows the standard options: Chrome控制台允许使用以下标准选项:

'ä'.localeCompare('z', 'de'); // -1
'ä'.localeCompare('z', 'sv'); // 1

Google Apps Script appears to ignore: Google Apps脚本似乎忽略了:

'ä'.localeCompare('z', 'de'); // -1
'ä'.localeCompare('z', 'sv'); // -1

Other options are similarly unavailable: 其他选项同样不可用:

// in German, ä has a as the base letter
'ä'.localeCompare('a', 'de', { sensitivity: 'base' });
// -> 0 in chrome,
// -> 1 in GAS

// in Swedish, ä and a are separate base letters
'ä'.localeCompare('a', 'sv', { sensitivity: 'base' });
// -> 1 in chrome
// -> 1 in GAS

Does it have anything to do with active user's locale? 它与活动用户的语言环境有关系吗? Or does GAS just have a stripped-down version of localeCompare? 还是GAS只是具有简化版本的localeCompare? Or am I doing it wrong? 还是我做错了?

does GAS just have a stripped-down version of localeCompare GAS是否只有一个简化版本的localeCompare

Yes, it does. 是的,它确实。 It runs on Rhino (a JS implementation in Java), in which localeCompare ignores all arguments after the first one. 它在Rhino(Java的JS实现)上运行,其中localeCompare忽略第一个参数之后的所有参数。 For example, 例如,

"a".localeCompare("b", "c", "d")

is obviously invalid in ECMAScript but runs in GAS, with the arguments "c" and "d" being silently ignored. 在ECMAScript中显然是无效的,但在GAS中运行,并且参数“ c”和“ d”被静默忽略。

This is somewhat similar to the situation with toLocaleString which acts as toString . 这有点类似于toLocaleString 充当toString的情况

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谷歌应用程序脚本中有哪些字符串文字可用? - what string literal is available in google apps script? 使用Google Apps脚本更改列表选项 - change list options using google apps script 该域是否可用或已被占用? 在 Google 表格应用程序脚本中 - Is this domain available or taken? In Google Sheets apps script 谷歌应用程序脚本html选择从电子表格数据加载的选项 - google apps script html select options loaded from spreadsheet data 如何使用 google Apps 脚本获取 json 阵列上可用的所有列表 - How to get all lists available on a json Array with google Apps script Node.js中的localeCompare选项意外结果 - localeCompare options in nodejs unexpected result Google Apps Script 中的 RegExMatch 等效项是什么? - What is the RegExMatch equivalent in Google Apps Script? 如果声明或不做什么? Gmail Google Apps脚本 - if statement or/not what to do? Gmail google apps script Google跟踪代码管理器和Google Apps脚本之间有什么区别? - What the differences are between Google Tag Manager and Google Apps Script? 许多数学函数在 Google Sheets Apps 脚本中不可用。 要使用 JavaScript 功能,是否有可用的完整指南 - Many math functions are not available in Google Sheets Apps Script. To use JavaScript functions, is there any complete guide available
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM