TizzyT

Stupid & Lazy -TizzyT

Mar 12th, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.08 KB | None | 0 0
  1.     'Imports System.Text
  2.     Public Function Lines(Optional ByVal line As UInteger = 0) As String
  3.         'Dim Store As New StringBuilder
  4.         Dim Store As String = String.Empty
  5.         For i As Integer = 0 To line
  6.             'Store.AppendLine()
  7.             Store &= vbCrLf
  8.         Next
  9.         'Return Store.ToString
  10.         Return Store
  11.     End Function
  12.  
  13.     Public Function ReadLn() As String
  14.         Return Console.ReadLine
  15.     End Function
  16.  
  17.     Public Function Read() As ConsoleKeyInfo
  18.         Return Console.ReadKey
  19.     End Function
  20.  
  21.     Public Sub PrintFancy(Optional ByVal Parts() As Object = Nothing)
  22.         If Parts IsNot Nothing AndAlso Parts.Length > 1 AndAlso Parts.Length Mod 2 = 0 Then
  23.             Dim Store As New StringBuilder
  24.             Dim args((Parts.Length / 2) - 1)
  25.             Dim Place As Integer = 0
  26.             For i = 1 To Parts.Length - 1 Step 2
  27.                 args(Place) = Parts(i)
  28.                 Place += 1
  29.             Next
  30.             For i = 0 To Parts.Length - 1 Step 2
  31.                 Try
  32.                     Store.AppendLine(String.Format(Parts(i), args))
  33.                 Catch ex As Exception
  34.                     Continue For
  35.                 End Try
  36.             Next
  37.             Console.WriteLine(Store.ToString)
  38.         Else
  39.             Console.WriteLine()
  40.         End If
  41.     End Sub
  42.  
  43.     '' Returns a new array that contains every Nth element from a given array starting from index 0
  44.     '' Offset is used to define which index to start with (less than the distance N)
  45.     Public Function Nth(Of T)(ByVal Array() As T, ByVal N As UInteger, Optional ByVal Offset As UInteger = 0) As T()
  46.         If N = 1 Then Return Array.Clone
  47.         If Math.Abs(Offset) <= N - 1 Then
  48.             Dim Store((Array.Length / N) - 1) As T, Place As Integer = 0
  49.             For i As UInteger = Offset To Array.Length - 1 Step N
  50.                 Store(Place) = Array(i)
  51.                 Place += 1
  52.                 If Place >= Store.Length Then Return Store
  53.             Next
  54.         End If
  55.         Throw New Exception("Offset must be less than the distance N")
  56.     End Function
Advertisement
Add Comment
Please, Sign In to add comment