當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Console.ReadLine方法代碼示例

本文整理匯總了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
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:45,代碼來源:Console.ReadLine

示例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
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:13,代碼來源:Console.ReadLine

輸出:

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
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:19,代碼來源:Console.ReadLine

輸出:

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
'       
'       >
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:22,代碼來源:Console.ReadLine

示例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
開發者ID:VB程序員,項目名稱:System,代碼行數:10,代碼來源:Console.ReadLine


注:本文中的System.Console.ReadLine方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。