VBScript:如何找到两个看起来相同的字符串之间的差异
在 VB 脚本中比较两个字符串“test_name”。它们必须相同,并且在调试查看器中看起来相同,但 StrCompare(string1, string2) 返回 1。
历史记录。 这是QTP中的测试。第一个字符串是从 Excel 中读取的。第二个来自 Windows 应用程序。 QTP 从 Excel 读取一个值,将其输入到 Windows 窗体中,然后从另一个地方读取相同的值。如果这两个值相同,则测试通过。
如何找到这两个字符串的差异以便我可以纠正测试?
There are two strings "test_name" that are compared in a VB script. They have to be identical, and they look identical in debug viewer, but StrCompare(string1, string2) returns 1.
History.
This is a test in QTP. The first string is read from Excel. The second one is from a windows application. QTP reads a value from Excel, enters it to a windows form, and then reads the same value from another place. The test passes if these two values are identical.
How to find a difference in these two strings so that I can correct the test?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议使用
For
循环、Mid
和Asc
来一一比较实际字符。像(未尝试的代码)这样的东西:如果通过这个测试它们相等,并且通过
StrComp
不相等,那么......我真的不知道。也许对LenB
和AscB
尝试同样的操作,看看是否是 Unicode 或编码问题。I would suggest using a
For
loop,Mid
, andAsc
, to compare the actual characters one by one. Something like (untried code):If they are equal by this test, and unequal by
StrComp
then... I don't really know. Perhaps try the same thing withLenB
andAscB
to see if it's a Unicode or encoding issue somehow.最有可能的是你在末尾有尾随空格(或者其他像空格一样打印的东西)。尝试像这样打印它们:
看看你会得到什么。
Most likely you have trailing spaces at the end (or something else that prints like a space). Try to print them like this:
and see what you get.
您是否尝试在
StrComnpare
中使用参数vbTextCompare
?这将对两个字符串进行不区分大小写的比较。
我也会推荐上面2位所说的。
所以应该是:
亲切的问候,
Did you try using the parameter
vbTextCompare
in yourStrComnpare
?This would do case-insensitive comparison of both strings.
I also would have recommended what the 2 above said.
So it would be:
Kind Regards,