asp读取字符串中指定的字符

2025-05-05 07:07:33
推荐回答(2个)
回答1:

''不好意思,代码没有环境调试
''很多错误没有直接发现,我帮你修正了,你不需要重新提问题
string=“显示器|4$键盘|2$主板|3$鼠标|6$硬盘|1$内存|2$键盘|1$鼠标|1$”
Dim i
Dim arrString, arrTemp
Dim arrResult(2,0)
arrString = Split(string, "$")
For i = 0 to UBound(arrString)
arrTemp = Split(arrString(i))
If UBound(arrTemp) = 1 Then
addArray arrTemp(0), arrTemp(1)
End If
Next

For i = 0 to UBound(arrResult, 2)
Response.Write arrResult(0, i) & "," & arrResult(1, i) & "," & arrResult(2, i)
Next

Function addArray (strName, intId)
Dim i, j
Dim blnHas
blnHas = false
For i = 0 to UBound(arrResult, 2)
If arrResult(0, i) = strName Then
blnHas = True
arrResult(1, i) = arrResult(1, i) & " , " & intId
arrResult(2, i) = arrResult(2, i) + 1
End If
Next
If not blnHas Then
j = UBound(arrResult, 2) + 1
Redim Preserve arrResult(2, j)
arrResult(0, j) = strName
arrResult(1, j) = intId
arrResult(2, j) = 1
End If
End Function

回答2:

给你个思路:可以考虑用split函数,用这个函数的目的是通过【$】做为分隔符进行分解,然后再通过FOR循环进行逐个判断,匹配就加1,不匹配则继续循环。