很简单,用字符串查找函数就可以实现了。
安徽网站建设公司成都创新互联公司,安徽网站设计制作,有大型网站制作公司丰富经验。已为安徽近千家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的安徽做网站的公司定做!
当在StrB查找到StrA字符串时,返回肯定是非0的数,值就是True,找不到为0或者-1,值就是Flase
比如:
Dim StrA As String = "Time is Limited"
Dim StrB As String = "Time"
Dim Stu As Boolean= InStr(StrA, StrB)
这运行段代码,Stu值就是True了。
我觉得这样最简单有效。
可以,用VB自带函数就可以了半角转全角:Text2.Text = StrConv(Text1.Text, )全角转半角:Text2.Text = StrConv(Text1.Text,vbNarrow)当然你可以做得智能一点,譬如只允许输入数字、符号和字母什么的。
substring 就是对一个指定的字符窜进行字符窜截取的方法。
运用的形式差不多如下:
截取后的字符窜 = 指定字符窜.substring(开始截取位置[第一位从0开始],截取长度)
Dim str As String = "dsk_cy"
Dim resultStr As String = str.substring(0,2)'截取最左边的两个字符 即 resultStr = “ds”
Dim reulst As String = str.substring(1,2) '截取从最左边数第二位开始的两个字符 即 result = “sk”
希望对你有帮助!
就是拆分字符串嘛用一个例子就知道了s=split("赵,钱,孙,李",",")s是个字符串数组,这样的话,s中就有四个元素s(0)是赵s(1)是钱s(2)是孙s(3)是李比自己一个个赋值快多了
Sub Main()
Dim arr As Integer() = {2, 3, 7, 8, 12, 23, 34, 44, 45, 68}
Dim txt As New StringBuilder("显示A中元素:")
For Each i As Integer In arr
txt.Append(i).Append(" ")
Next
Console.WriteLine(txt.ToString)
Console.WriteLine("请输入查找数值:")
Dim num As Integer = CInt(Val(Console.ReadLine))
Console.WriteLine("你输入的数据是:" num.ToString)
Dim loca As Integer = Array.IndexOf(arr, num) + 1
If loca = 0 Then
Console.WriteLine(num "的位置在第" loca "个")
Else
Console.WriteLine("数组中无" num)
End If
Console.ReadLine()
End Sub
数组中搜索匹配值的索引,如果数组中没有重复的值,没必要弄那么复杂的循环,IndexOf函数就搞定了。
如果有重复的,用下面的循环,可以返回多个匹配值的索引;
Sub Main()
Dim arr As Integer() = {2, 3, 7, 8, 12, 12, 12, 23, 34, 44, 45, 68}
Dim txt As New StringBuilder("显示A中元素:")
For Each i As Integer In arr
txt.Append(i).Append(" ")
Next
Console.WriteLine(txt.ToString)
Console.WriteLine("请输入查找数值:")
Dim num As Integer = CInt(Val(Console.ReadLine))
Console.WriteLine("你输入的数据是:" num.ToString)
Dim length As Integer, counts As Integer() = New Integer() {}
For i As Integer = 0 To arr.Length - 1
If arr(i) = num Then
length = counts.Length
ReDim Preserve counts(length) : counts(length) = (i + 1)
End If
Next
length = counts.Length - 1
If length 0 Then
txt = New StringBuilder
txt.Append(num).Append("的位置在第")
For i As Integer = 0 To length
txt.Append(counts(i))
If i length Then txt.Append("|")
Next
txt.Append("个")
Console.WriteLine(txt.ToString)
Else
Console.WriteLine("数组中无" num)
End If
Console.ReadLine()
End Sub