Imports System.Text.RegularExpressions Public Class Form1 Private table As DataTable Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load table = CreateTable() AddRow("*****A1") AddRow("*****B1") AddRow("*****A10") AddRow("*****A2") AddRow("*****A3") AddRow("*****A") ListBox1.DisplayMember = "Value" ListBox1.DataSource = table Button1.Text = "昇順" Button2.Text = "降順" Button3.Text = "数字だけ降順" Button4.Text = "登録順" End Sub Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click table.DefaultView.Sort = "head, key, num" End Sub Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click table.DefaultView.Sort = "head DESC, key DESC, num DESC" End Sub Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click table.DefaultView.Sort = "head, key, num DESC" End Sub Private Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click table.DefaultView.Sort = Nothing End Sub Private ReadOnly Pattern As New Regex("(?<head>^.*)(?<key>[a-zA-Z])(?<num>\d{0,2}$)") Private Sub AddRow(ByVal value As String) Dim m As Match = Pattern.Match(value) Dim newRow As DataRow = table.NewRow() newRow("Value") = value If m.Success Then newRow("Head") = m.Groups("head").Value newRow("Key") = CChar(m.Groups("key").Value) If m.Groups("num").Length > 0 Then newRow("Num") = CInt(m.Groups("num").Value) End If End If table.Rows.Add(newRow) End Sub Private Shared Function CreateTable() As DataTable Dim tbl As New DataTable() tbl.Columns.Add("Value", GetType(String)) tbl.Columns.Add("Head", GetType(String)) tbl.Columns.Add("Key", GetType(Char)) tbl.Columns.Add("Num", GetType(Integer)) Return tbl End Function End Class