vb.net 控制台读取输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6150998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:31:09  来源:igfitidea点击:

Console read input

vb.netconsole-application

提问by Cobold

How to create a console application which would read input from user and assign the input to a variable? The problem is, I need to enter several words on one line separated with blank spaces like "ab cd efg" and then assign ab to one variable, cd to another variable and efg to another variable. Also the entered words can be any lenght.

如何创建一个控制台应用程序来读取用户的输入并将输入分配给一个变量?问题是,我需要在一行中输入几个用空格分隔的单词,例如“ ab cd efg”,然后将 ab 分配给一个变量,将 cd 分配给另一个变量,将 efg 分配给另一个变量。输入的单词也可以是任何长度。

回答by aligray

Dim input = Console.ReadLine()
Dim tokens As String() = input.Split(" ")

回答by Fredrik M?rk

Is this homework? I'll keep the answer from being too concrete, but you will want to learn more about Console.ReadLineand String.Split. We can start there.

这是家庭作业吗?我不会让答案过于具体,但您会想要了解更多关于Console.ReadLine和 的信息String.Split。我们可以从那里开始。

回答by Akram Shahda

You can use Console.Read, Console.ReadLineand String.Splitmethods to accomplish this task.

您可以使用Console.ReadConsole.ReadLineString.Split方法来完成此任务。

Good luck.

祝你好运。