عملت لك دالة خاصة لمشروعك وضيفتها تحويل هذه السلسة النصية الخاصة إلى Datatable لكي يسهل التعامل مع بيانتها في البحث بسهول باستخدام Linq
كود :
#Region " StringToDatatable "
Function StringToDatatable(ByVal s As String) As DataTable
Dim mDataTable As New DataTable
mDataTable.Columns.AddRange(New DataColumn() {New DataColumn("id"), New DataColumn("customer"), New DataColumn("name"), New DataColumn("actual-profile")})
mDataTable.Columns.AddRange(New DataColumn() {New DataColumn("password"), New DataColumn("shared-users"), New DataColumn("wireless-psk")})
mDataTable.Columns.AddRange(New DataColumn() {New DataColumn("wireless-enc-key"), New DataColumn("wireless-enc-algo"), New DataColumn("last-seen")})
mDataTable.Columns.AddRange(New DataColumn() {New DataColumn("active"), New DataColumn("incomplete"), New DataColumn("disabled")})
Dim q =
From x As String
In (From x As System.Text.RegularExpressions.Match In System.Text.RegularExpressions.Regex.Matches(s, "(?<=!re).+?(?=!)") Select x.Value)
Select New user With {
.id = System.Text.RegularExpressions.Regex.Match(x, "(?<==.id=).*?(?==)").Value,
.customer = System.Text.RegularExpressions.Regex.Match(x, "(?<==customer=).*?(?==)").Value,
.name = System.Text.RegularExpressions.Regex.Match(x, "(?<==name=).*?(?==)").Value,
.actual_profile = System.Text.RegularExpressions.Regex.Match(x, "(?<==actual-profile=).*?(?==)").Value,
.password = System.Text.RegularExpressions.Regex.Match(x, "(?<==password=).*?(?==)").Value,
.shared_users = System.Text.RegularExpressions.Regex.Match(x, "(?<==shared-users=).*?(?==)").Value,
.wireless_psk = System.Text.RegularExpressions.Regex.Match(x, "(?<==wireless-psk=).*?(?==)").Value,
.wireless_enc_key = System.Text.RegularExpressions.Regex.Match(x, "(?<==wireless-enc-key=)*?(?==)").Value,
.wireless_enc_algo = System.Text.RegularExpressions.Regex.Match(x, "(?<==wireless-enc-algo=).*?(?==)").Value,
.last_seen = System.Text.RegularExpressions.Regex.Match(x, "(?<==last-seen=).*?(?==)").Value,
.active = System.Text.RegularExpressions.Regex.Match(x, "(?<==active=).*?(?==)").Value,
.incomplete = System.Text.RegularExpressions.Regex.Match(x, "(?<==incomplete=).*?(?==)").Value,
.disabled = System.Text.RegularExpressions.Regex.Match(x, "(?<==disabled=).*").Value
}
For Each u As user In q
mDataTable.Rows.Add(u.id, u.customer, u.name, u.actual_profile, u.password, u.shared_users, u.wireless_psk, u.wireless_enc_key,
u.wireless_enc_algo, u.last_seen, u.active, u.incomplete, u.disabled)
Next
Return mDataTable
End Function
Structure user
Dim id As String
Dim customer As String
Dim name As String
Dim actual_profile As String
Dim password As String
Dim shared_users As String
Dim wireless_psk As String
Dim wireless_enc_key As String
Dim wireless_enc_algo As String
Dim last_seen As String
Dim active As String
Dim incomplete As String
Dim disabled As String
End Structure
#End Region