How to debug identical strings that do not equal in google app script?

别来无恙 提交于 2021-02-02 08:53:02

问题


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:


  1. Consider type of each variable

    typeof string1 === typeof string2
    
  2. Consider length of each string

     string1.length === string2.length
    
  3. Loop through each character:

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


来源:https://stackoverflow.com/questions/63062562/how-to-debug-identical-strings-that-do-not-equal-in-google-app-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!