【问题标题】:What is the right operator in vb.net for test if a String is not equal? [duplicate]如果字符串不相等,vb.net 中用于测试的正确运算符是什么? [复制]
【发布时间】:2019-03-19 14:08:52
【问题描述】:

我试过这样的

Do Until !test.equals("1234") Or !test.equals("xyxyxyx")  
... 
Loop

如何在 vb.net 中编写?

【问题讨论】:

  • <> 是 VB.NET 值不等式运​​算符,您可以很容易地找到它,所以如果您使用它并且没有得到预期的结果,那么您做错了。也许展示并解释你想要发生的事情,而不是期望我们从不这样做的代码中解决它。
  • 尝试使用Not 而不是!。 Do Until Not 1 = 2
  • @dieMstar - 循环永远不会运行,因为 test 不能等于两个不同的值。

标签: string vb.net inequality


【解决方案1】:

!在其他语言中不是 vb.net

Do Until Not test.equals("1234") Or Not test.equals("xyxyxyx")  

【讨论】:

  • 对于那些不完全了解 VB 在使用比较运算符 (=, <>, >, <, >=, <=, etc.) 时重写字符串比较方式的人来说,这种语法是获得预期结果的最安全选择。由于编译器选项或每个代码文件指令,字符串类的Equals 方法永远不会产生不同的结果。
【解决方案2】:

我相信这就是您正在寻找的:

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference///operators/comparison-operators

Do Until test <> 1234 Or test <> "xyxyxyx"
... 
Loop

【讨论】:

    【解决方案3】:

    试试这个 Do While test <> "1234" or test <> "xyxyxyx" //your code here... Loop

    来自微软文档

    Do Loop Statement(visual Basic)

    Comparison operators in Visual Basic

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多