TizzyT

Joes Formatter -TizzyT

Oct 26th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.04 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Text
  3.  
  4. Module Module1
  5.  
  6.     Sub Main()
  7.         Dim args() As String = My.Application.CommandLineArgs.ToArray
  8.         For Each arg As String In args
  9.             If arg.ToLower.EndsWith(".txt") Then
  10.                 Dim meh As New StringBuilder()
  11.                 Using sr As New StreamReader(arg)
  12.                     While sr.Peek <> -1
  13.                         meh.AppendLine(Formatter(sr.ReadLine))
  14.                     End While
  15.                 End Using
  16.                 IO.File.WriteAllText(arg.Replace(".txt", "_Formatted.txt"), meh.ToString)
  17.             End If
  18.         Next
  19.     End Sub
  20.  
  21.     Private Function Formatter(ByVal line As String) As String
  22.         If line.StartsWith(">") Then
  23.             Dim parts() As String = line.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries)
  24.             If parts(0).StartsWith(">") Then parts(0) = parts(0).Substring(1)
  25.             Return "> " & parts(1) & " " & parts(2) & " " & parts(0)
  26.         End If
  27.         Return line
  28.     End Function
  29. End Module
Advertisement
Add Comment
Please, Sign In to add comment