大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
如果用常规编程的方法:
成都创新互联专业为企业提供新洲网站建设、新洲做网站、新洲网站设计、新洲网站制作等企业网站建设、网页设计与制作、新洲企业网站模板建站服务,10余年新洲做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
直接用split(str1,“,”)的形式把str1字符串分成字符串数组,然后用for循环判断每个数组元素是否是数字或者是字符串就可以了。
用数组呗。我是用VB6的,不过你会.NET也肯定能看懂。
不是文本文件么?先用Line Input读每行存入数组。再把每行数据用你的","分割,就可以查询了。我写个简单的例子:
'搜索函数,用法Search(标头,序号),返回数据.
Private Function Search(ByVal Section As String, ByVal Index As Integer) As String
Dim fNum%, Lines%, temp%, Str As String
ReDim Data(0)
fNum = FreeFile()
If Dir("C:\\1.txt") = "" Then Exit Function
'文件路径和文件名你自己改
Open "C:\\1.txt" For Input As #fNum
Do While Not EOF(fNum)
Lines = Lines + 1
'行数
Line Input #fNum, Str
ReDim Preserve Data(Lines)
Data(Lines) = Str
Loop
Close #fNum
If Lines 0 Then
Dim tmp() As String
For temp = 1 To UBound(Data)
tmp = Split(Data(temp), ",")
'分割
If tmp(0) = Section Then
Search = tmp(Index - 1)
'因为从0开始所以-1
Exit Function
End If
Next
End If
End Function
比如你要“gc“开头的第5个数据,就用Search("gc",5)即可返回45。
Dim str As String = "", temp, n As Integer
Dim str1 As String = "12,45,2,9,41,31,66,83,2,1,-9,-91,-21"
Dim a() As String = Split(str1, ",")
For i = 1 To UBound(a) Step 1
a(i) = Val(a(i))
Next
temp = 0
n = 0
For i = 1 To UBound(a)
If a(i) temp Then
temp = a(i)
End If
If a(i) 0 Then
n = n + 1
End If
Next
str = str "正数的个数为 " n
str = str "最大元素的下标为 "
For i = 1 To UBound(a)
If a(i) = temp Then
str = str i " "
End If
Next
TextBox6.Text = str