Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bcabeb4

Browse files
ReadLines + ReadBytes
1 parent 31314df commit bcabeb4

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

‎demo/ReadText.Demo.VB/Program.vb‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1-
Module Program
1+
Imports System
2+
Imports System.IO
3+
Imports System.Linq
4+
Imports System.Text
5+
Imports CommandLine
26

3-
Sub Main()
7+
Module Program
8+
9+
Sub Main(ByVal sArgs() As String)
410

511
End Sub
612

13+
Private Function ReadLines(fileName As String, fromTop As Boolean, count As Integer) As String
14+
15+
Dim lines = File.ReadAllLines(fileName)
16+
If (fromTop) Then
17+
Return String.Join(Environment.NewLine, lines.Take(count))
18+
End If
19+
20+
Return String.Join(Environment.NewLine, lines.Reverse().Take(count))
21+
22+
End Function
23+
24+
Private Function ReadBytes(fileName As String, fromTop As Boolean, count As Integer) As String
25+
26+
Dim bytes = File.ReadAllBytes(fileName)
27+
If (fromTop) Then
28+
Return Encoding.UTF8.GetString(bytes, 0, count)
29+
End If
30+
31+
Return Encoding.UTF8.GetString(bytes, bytes.Length - count, count)
32+
33+
End Function
34+
735
End Module

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /