
正文
vb.net数组查找字段 vb在数组中查找指定元素
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.net 查询数据库中一字段中二个字符中间的值
DataTable dt;//假设 dtvb.net数组查找字段的第一列存储vb.net数组查找字段的就是这个str1_1vb.net数组查找字段,str2_1vb.net数组查找字段,str3_1vb.net数组查找字段,str4_1,则
foreach(DataRow dr in dt.Rows)
{
String s=dr[0].ToString();
String[] strs=s.split('_');//得到 str1,1 形式的数组(str2,1 str3,1 str4 ,1 )
String s2=strs[0];//取数组第一个,如 str1,str2,str3,str4 等
String[] strs2=s2.split('r');//得到st,1形式的数字
String 结果=strs2[1];//取第一个,得到如 1,2,3,4等结果就是lz需要的
}
相关问答
Q1: vb.net 查询Access数据库的多个字段
假设textbox2.text
内容为“abc”,在三个字段中查找内容等于它的记录,则:
select
*
from
你的表名
where
'abc'
in(字段1,字段2,字段3)
Q2: 如何在VB的数组中查找数据?
有序数的快速查找方法(非递归法)
Private Sub Command1_Click()
Dim dd(27) As Long
Dim aa As Long
Dim v As Long
dd(0) = 75
dd(1) = 80
dd(2) = 85
dd(3) = 90
dd(4) = 95
dd(5) = 100
dd(6) = 106
dd(7) = 112
dd(8) = 118
dd(9) = 125
dd(10) = 132
dd(11) = 140
dd(12) = 150
dd(13) = 160
dd(14) = 180
dd(15) = 200
dd(16) = 224
dd(17) = 250
dd(18) = 280
dd(19) = 315
dd(20) = 355
dd(21) = 400
dd(22) = 450
dd(23) = 500
dd(24) = 560
dd(25) = 630
dd(26) = 710
dd(27) = 800
aa = 280 '要查找的数字
v = NumFind(dd, aa) '调用查找函数
If v = -1 Then
MsgBox "没发现要查找的数据", vbExclamation, "提示"
Else
MsgBox "当前要查找的:" aa " 值在dd数组的第:" v " 个元素。", vbInformation, "信息"
End If
End Sub
Public Function NumFind(ByRef Myarray, FNumber As Variant) As Long
Dim K As Long, I As Long
Dim L1 As Long, R1 As Long
Dim l As Long, R As Long
l = LBound(Myarray): R = UBound(Myarray)
NextLoop:
K = (l + R) Mod 2
If K = 1 Then '中点
I = (l + R + 1) \ 2
Else
I = (l + R) \ 2
End If
If Myarray(I) FNumber Then
If Myarray(I) FNumber Then
L1 = l: R1 = I
Else
L1 = I: R1 = R
End If
If (R1 - L1) = 1 Then '第一个和最后一个
If Myarray(L1) = FNumber Then
NumFind = L1
ElseIf Myarray(R1) = FNumber Then
NumFind = R1
Else
NumFind = -1 '没有发现
End If
Else
l = L1: R = R1
GoTo NextLoop
End If
Else
NumFind = I
End If
End Function
Q3: 在asp VB.NET怎么查找一维数组中特定字符串
先遍历数组:
for i = 0 to Ubound(数组)
...
next
再把中间的...替换成:
if 数组(i) = 特定的字符 then msgbox "找到鸟,当前是:数组" i
Q4: vb.net byte数组中怎样搜索特定的byte值
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a() As Byte = System.IO.File.ReadAllBytes("record.db")
For Index As Integer = a.GetLowerBound(0) To a.GetUpperBound(0) - 3
If a(Index) = 56 AndAlso a(Index + 1) = 57 AndAlso a(Index + 2) = 58 AndAlso a(Index + 3) = 59 Then
Debug.Print(Index.ToString) '输出byte串位置
End If
Next
End Sub
End Class
刚学,不知道有没有直接在数组中搜索一串元素的方法。
Q5: vb.net如何在数组中查找数组?
'''这个函数功能就是用来把数组转为string的格式'''如byte()={1,2,3,4,5,6}转化后变为",1,2,3,4,5,6,"Function ByteArrayToString(bytes() As Byte) As String Dim s As String = "" For i As Integer = 0 To bytes.Length s = Convert.ToString(bytes(i)) "," Next Return “," sEnd Function Sub Search()Dim a as byte()={1,2,3,4,5,6}
Dim b as byte()={2,3,4}
Dim astr As String = ByteArrayToString(a)Dim bstr As String = ByteArrayToString(b)Dim index As Integer = astr.IndexOf(bstr) '这个index就是b数组在a数组的位置vb.net数组查找字段,下标从0开始,不过记得处理下逗号,因为这时候是字符串。'''如果index小于0说明没有匹配内容End Sub 现在说明下ByteArrayToString为什么要在字符串开头加个",",如果不加,可能出现a="1,23,4,5,6,", b="3,4,5,",结果导致查询位置错误,匹配vb.net数组查找字段了a的位置
关于vb.net数组查找字段和vb在数组中查找指定元素的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







