【问题标题】:(Select Case) If textbox contains "phrase" then output(选择案例)如果文本框包含“短语”,则输出
【发布时间】:2017-09-22 00:12:29
【问题描述】:

我正在制作一个简单的聊天机器人,就像我的朋友一样。

(示例)如果 inputtxt 包含单词“water”,则 outputtxt 会显示“Waterfall from the sky”。因此,如果 inputtxt 说“你觉得 water 怎么样”,它会识别 water 并说“水从天上掉下来。”

我整天都在搞砸它,但无法得到它。我也希望它采用特定案例形式。

【问题讨论】:

  • 请阅读How to Ask 并使用tour。也许如果您发布代码有人可以提供帮助。照原样,我们必须猜测出什么问题
  • 如果你整天都在搞砸它,你确定你已经设法进行一些尝试了吗?

标签: vb.net select-case


【解决方案1】:

你是这个意思吗?

Private Sub inputtxt_TextChanged(sender As Object, e As EventArgs) Handles inputtxt.TextChanged
    Dim input As String = inputtxt.Text
    Select Case input
        Case input = "water"
            outputtxt.Text = "Water falls from the sky."
        Case input = "What do you think of water"
            outputtxt.Text = "Water falls from the sky."
        Case Else
            outputtxt.Text = "Please input a string!!"
    End Select
End Sub

【讨论】:

    【解决方案2】:

    我明白了。我做了以下

        Dim InputStringDing As String = InputTxtBox.Text.ToLower
        Select Case True
            Case InputStringDing.Contains("water")
                OutputRTB.Text += "Tommy: " & "Water falls from the sky!"
        End Select
    

    我真的要感谢投反对票的人。这是帮助尝试学习 vb 的人的一个非常好的方法。如果其他人有同样的问题怎么办?他们不想点击 -1 吗?我看到了非常好的社区。​​p>

    感谢您的帮助

    【讨论】:

      【解决方案3】:
      If textbox.text.Contains("water") then output = "Water falls from the sky."
      

      我不建议您为此使用选择案例。“如果”会更好

      【讨论】:

      • 它会,但我不仅仅是“水”,而且选择案例不是添加越来越多的其他然后是
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      • 1970-01-01
      • 2012-09-04
      • 1970-01-01
      • 2012-11-10
      • 2012-08-04
      • 2018-01-05
      相关资源
      最近更新 更多