Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim a As String
Dim m As Integer = 20
Dim myString() As String
Dim i As Integer
'Left(strString,21)
a = Me.TextBox1.Text
myString = a.Split(" ")
For i = 0 To UBound(myString) Step 1
Me.lblText.Text = Me.lblText.Text & " " & myString(i)
If i = m Then
Me.lblText.Text += "<br>"
m = m + 20
End If
Next
End Sub
จากที่ได้ลองศึกษา Function ตามที่บอกข้างต้นนะครับผมเขียนออกมาได้ดังนี้
Code (VB.NET)
Sub Main()
'Dim r As String
Dim a As String
Dim m As Integer = 20
Dim n As Integer = 5
Dim myString() As String
Dim i As Integer
a = Me.TextBox1.Text
'Me.lblText.Text = ""
Dim strName As String = me.TextBox1.Text
Dim strRegularPattern As String = "[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]"
Dim strThaiPettern As String = "[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮ]"
Dim strTatalPettern As String = "[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzกขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮ]"
If Regex.IsMatch(strName, strRegularPattern) Then
myString = a.Split(" ")
For i = 0 To UBound(myString) Step 1
Me.lblText.Text = Me.lblText.Text & " " & myString(i)
If i = m Then
Me.lblText.Text += "<br>"
m = m + 20
End If
Next
ElseIf Regex.IsMatch(strName, strThaiPettern) or Regex.IsMatch(strName, strTatalPettern) Then
myString = a.Split(" ")
For i = 0 To UBound(myString) Step 1
Me.lblText.Text = Me.lblText.Text & " " & myString(i)
If i = n Then
Me.lblText.Text += "<br>"
n = n + 20
End If
Next
End If
End Sub