ネタ元:[C++] 縦書き
VB2005でやってみた。
Module Yoko2Tate
Sub Main(ByVal args() As String)
Dim dest() As String
Using sr As New System.IO.StreamReader(args(0), System.Text.Encoding.GetEncoding("Shift_JIS"))
Dim buf As String = sr.ReadToEnd
Dim src() As String = Split(buf, vbCrLf)
Dim maxlength As Integer = 0
For rowcount As Integer = 0 To src.Length - 1
If src(rowcount).Length > maxlength Then maxlength = src(rowcount).Length
Next
ReDim dest(maxlength)
For colcount As Integer = 0 To maxlength - 1
For rowcount As Integer = src.Length - 1 To 0 Step -1
If src(rowcount).Length < maxlength Then src(rowcount) = (src(rowcount) & New String(CChar(" "), maxlength)).Substring(0, maxlength)
dest(colcount) = dest(colcount) & src(rowcount).Substring(colcount, 1)
Next
Next
sr.Close()
End Using
Using sr As New System.IO.StreamWriter(args(1), False, System.Text.Encoding.GetEncoding("Shift_JIS"))
For rowcount As Integer = 0 To dest.Length - 1
sr.WriteLine(dest(rowcount))
Next
sr.Close()
End Using
End Sub
End Module
現状で27行のコードですが、StreamReaderとかStreamWriterのCloseせずUsing-End Usingなどの安全策も除いちゃうと23行になります。
:でFor~Nextを1行にしちゃうような事はあえてしてないですが、単独ループではなく「If src(rowcount).Length < maxlength Then 」で空白補完のループを省略したのは内緒www