タイトル | : Re^3: Split関数について |
記事No | : 9965 |
投稿日 | : 2010/03/10(Wed) 14:17 |
投稿者 | : 魔界の仮面弁士 |
> 列数がバラバラなのが気になりますが、 > こんなこと出来ますでしょうか? > A(1,1) A(1,2) A(1,3) A(1,4) *** *** **** *** > A(2,1) A(2,2) A(2,3) ** ** * > A(3,1) A(3,2) A(3,3) A(3,4) A(3,5) * *** * ** ** > よろしくお願いいたします。
二次元配列の代わりに、ジャグ配列を使うのは如何でしょうか。 たとえば、このような結果を得ることができます。
A(0)(0) = "***" A(0)(1) = "***" A(0)(2) = "****" A(0)(3) = "***"
A(1)(0) = "**" A(1)(1) = "**" A(1)(2) = "*"
A(2)(0) = "*" A(2)(1) = "***" A(2)(2) = "*" A(2)(3) = "**" A(2)(4) = "**"
------------------------- Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load TextBox1.Multiline = True TextBox1.Height = 80 TextBox1.Text = "*** *** **** ***" & vbNewLine & "** ** *" & vbNewLine & "* *** * ** **" End Sub
Private Function GetArray(ByVal s As String) As String()() Dim options As StringSplitOptions = StringSplitOptions.RemoveEmptyEntries Dim lines As New List(Of String()) For Each line As String In Split(s, vbNewLine) lines.Add(line.Split(New String() {}, options)) Next Return lines.ToArray() End Function
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Dim A()() As String = GetArray(TextBox1.Text)
End Sub
|