【问题标题】:Program won't give correct number- Console application程序不会给出正确的数字 - 控制台应用程序
【发布时间】:2018-10-25 11:48:30
【问题描述】:

问题
我试图在 VB 中编写一个程序,因为我想尝试一下这种语言。但它没有给出具体的结果。这不工作在逻辑上是没有意义的。因此,如果有人能给我一个解释和答案,那就太好了。
目标:
给出了一系列数字,但有些在括号中,例如 (01234)567890。我想要做的是从数字中删除这些括号,但由于某种原因我的尝试不起作用。

我的尝试:

Sub Main()
      Dim input, output, ds, sd as string
      Dim s, f as integer
      Console.writeline(" enter number ")
      Input = Console.readline
      s = Instr(input, "(")
      f = InStr(input, ")")
      ds = input.Substring(s, f - 1)
      Sd = input.Substring( f - 1)
     Input = ds + sd
     Console.writline(output)
     Console.Readline()
End sub

输出:

01234)567890

注意:请忽略任何拼写错误,因为这是从我的手机上传的,我想澄清一下,我主要用其他语言编写代码。

【问题讨论】:

  • 你想去掉括号还是去掉里面的数字?
  • 另外,我看到我不知道你是如何获得该输出的,因为在你的代码中你从不使用输出变量,而且你写了writline 而不是writeline 那不会'甚至编译...
  • 如果您正在学习 VB,我建议您不要使用旧的 InStr 函数,而是使用 .NET 框架中的字符串函数。
  • @Brank-Victoria 首先,“P.S 忽略任何拼写错误,因为它是从手机上传的”我认为这已经足够清楚了。该程序仅删除括号,而不是其中的数字。
  • 那么你只需要将那些字符替换为空白,就像 Nithin 的回答一样

标签: vb.net console console-application


【解决方案1】:

希望对你有帮助

Sub Main()
    Dim input, input1 As String
    Console.WriteLine(" enter number ")
    input = Console.ReadLine
    input1 = input.Replace("(", String.Empty).Replace(")", String.Empty)
    Console.WriteLine(input1)
    Console.ReadLine()
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多