本文介绍了如何调试在谷歌应用程序脚本中不相等的相同字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个相同的字符串,它们在调试器(和 Logger.log)中显示相同,但​​是当我执行 string1 === string2 时,它返回 false.我该如何调试?

I have 2 identical strings, they appear identical in the debugger (and Logger.log), but when I do string1 === string2 it returns false. How can I debug this?

其中一个字符串是谷歌驱动器文件名,另一个字符串来自谷歌工作表单元格.我猜其中一个字符串中有一个不可见的字符,但我无法看到它.

One of the string is a google drive file name, and one of the string is from a google sheet cell. I'm guessing there's an invisible character in one of the string but I have no way to see it.

推荐答案

  1. 考虑每个变量的type

typeof string1 === typeof string2

  • 考虑每个字符串的长度

     string1.length === string2.length
    

  • 遍历每个字符:

  • Loop through each character:

     [...string1].every((char,i) => char === string2[i] || console.info(`Unequal character at ${i}`))
    

  • 这篇关于如何调试在谷歌应用程序脚本中不相等的相同字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-04 13:06
    查看更多