Google Apps脚本中的字符串平等
我正在尝试比较从JSON对象中检索的名称,并在Google表上使用该名称。尽我所能,我无法获得带来积极的比较。 我已经尝试过:
indexof
localecompare
==
=====
我尝试过 键===值
字符串(键)=== String(value)
和 string(键).valueof()=字符串(value).valueof
。 我还尝试在所有内容上调用trim()
以确保没有领先/拖延的白色空间(没有,如length()
比较所确认 从屏幕截图中可以看到,
键
和value
的值完全相同。 任何指针都会非常感激。这已经使我的项目持续了好几天!
I'm trying to compare a name retrieved from a JSON object, with a name as it exists on a google Sheet. Try as I might, I can't get a comparison that yields a positive.
I've tried:
IndexOf
localeCompare
==
===
I've triedkey===value
String(key)===String(value)
andString(key).valueof()=String(value).valueof
.
I've also tried calling trim()
on everything to make sure there are no leading/trailing white spaces (there aren't, as confirmed with a length()
comparison.
As you can see from the screen shot, the values of key
and value
are exactly the same.
Any pointers would be gratefully received. This has held up my project for days!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
描述
这不是解决方案,但可能有助于找到问题。也许一个或另一个角色不是您的想法。在视觉上它们比较,但是如果一个人有一个标签而不是空间,该怎么办。尝试一下,列出每个字符代码,看看任何字符是否具有不同的值。
我添加了另一个选项,该选项可借助@themaster
脚本(选项1)
脚本(选项2)
执行日志
Description
This is not a solution but it might help find the problem. Perhaps the characters in one or the other is not what you think. Visually they compare, but what if one has a tab instead of a space. Try this, list the character codes for each and see if any character has a different value.
I've added another option that eliminates the for loop thanks to @TheMaster
Script (Option 1)
Script (Option 2)
Execution log
比较表
:
Compare
Sheet1: