本文整理汇总了VB.NET中System.Console.ReadLine方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Console.ReadLine方法的具体用法?VB.NET Console.ReadLine怎么用?VB.NET Console.ReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Console
的用法示例。
在下文中一共展示了Console.ReadLine方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: InsertTabs
' 导入命名空间
Imports System.IO
Public Module InsertTabs
Private Const tabSize As Integer = 4
Private Const usageText As String = "Usage: INSERTTABS inputfile.txt outputfile.txt"
Public Function Main(args As String()) As Integer
If args.Length < 2 Then
Console.WriteLine(usageText)
Return 1
End If
Try
' Attempt to open output file.
Using writer As New StreamWriter(args(1))
Using reader As New StreamReader(args(0))
' Redirect standard output from the console to the output file.
Console.SetOut(writer)
' Redirect standard input from the console to the input file.
Console.SetIn(reader)
Dim line As String = Console.ReadLine()
While line IsNot Nothing
Dim newLine As String = line.Replace("".PadRight(tabSize, " "c), ControlChars.Tab)
Console.WriteLine(newLine)
line = Console.ReadLine()
End While
End Using
End Using
Catch e As IOException
Dim errorWriter As TextWriter = Console.Error
errorWriter.WriteLine(e.Message)
errorWriter.WriteLine(usageText)
Return 1
End Try
' Recover the standard output stream so that a
' completion message can be displayed.
Dim standardOutput As New StreamWriter(Console.OpenStandardOutput())
standardOutput.AutoFlush = True
Console.SetOut(standardOutput)
Console.WriteLine($"INSERTTABS has completed the processing of {args(0)}.")
Return 0
End Function
End Module
示例2: Example
Module Example
Public Sub Main()
Console.Clear()
Dim dat As Date = Date.Now
Console.WriteLine()
Console.WriteLine("Today is {0:d} at {0:T}.", dat)
Console.WriteLine()
Console.Write("Press any key to continue... ")
Console.ReadLine()
End Sub
End Module
输出:
Today is 10/26/2015 at 12:22:22 PM. Press any key to continue...
示例3: Example
Module Example
Public Sub Main()
If Not Console.IsInputRedirected Then
Console.WriteLine("This example requires that input be redirected from a file.")
Exit Sub
End If
Console.WriteLine("About to call Console.ReadLine in a loop.")
Console.WriteLine("----")
Dim s As String
Dim ctr As Integer
Do
ctr += 1
s = Console.ReadLine()
Console.WriteLine("Line {0}: {1}", ctr, s)
Loop While s IsNot Nothing
Console.WriteLine("---")
End Sub
End Module
输出:
About to call Console.ReadLine in a loop. ---- Line 1: This is the first line. Line 2: This is the second line. Line 3: This is the third line. Line 4: This is the fourth line. Line 5: ---
示例4: Example
Module Example
Public Sub Main()
Dim line As String
Console.WriteLine("Enter one or more lines of text (press CTRL+Z to exit):")
Console.WriteLine()
Do
Console.Write(" ")
line = Console.ReadLine()
If line IsNot Nothing Then Console.WriteLine(" " + line)
Loop While line IsNot Nothing
End Sub
End Module
' The following displays possible output from this example:
' Enter one or more lines of text (press CTRL+Z to exit):
'
' This is line #1.
' This is line #1.
' This is line #2
' This is line #2
' ^Z
'
' >
示例5: Console.ReadLine()
Module Module1
Sub Main()
Dim strMessage As String
Try
strMessage = Console.ReadLine()
Console.WriteLine("HELLO " + strMessage)
Catch ex As Exception
End Try
End Sub
End Module