• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET Console.SetError方法代码示例发布时间:2022-05-24
下一篇:
VB.NET Keys枚举代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap