Ich habe ein Suchfeld.
Mein Admin-Benutzer sucht möglicherweise nach "@MG @EB dorchester".
In ASP muss ich zählen, wie oft das Symbol "@" in der Zeichenfolge angezeigt wird. Wie ist das möglich?
Versuche dies:
len(yourString) - len(replace(yourString, "@", ""))
Für JW01
Dim pos : pos = 0
Dim count : count = -1
Do
count = count + 1
pos = InStr(pos + 1, str, "@")
Loop While (pos > 0)
Versuchen Sie eine while-Schleife:
Do While (str.indexOf("@") != -1)
count = count + 1
str = right(str, len(str) - str.indexOf("@"))
Loop
EDIT:
Diese for-Schleife könnte sinnvoller sein:
dim strLen, curChar, count
count = 0
int strLen = len(str)
for i = 1 to strLen
curChar = mid(str, i, 1)
if curChar = "@"
count = count + 1
end if
next
Response.write ubound(split(str,"@"))
reicht aus, um das Auftreten eines bestimmten Zeichens zu zählen
Ersetzen Sie die Suche durch ein Leerzeichen und finden Sie den Unterschied zwischen der ursprünglichen und der neuen Zeichenfolge. Gibt an, wie oft eine Zeichenfolge vorhanden ist
Dim a = "I @ am @ [email protected]"
Dim count
count = Len(a) - Len(Replace(a,"@",""))
Response.write count
Function FnMatchedStringCountFromText(strText,strStringToSearch)
strLength = Len(strText)
strNumber = 1
IntCount = 0
For i = 1 to strLength
If Instr(1,strText,strStringToSearch,0) > 0 Then
stMatch = Instr(1,strText,strStringToSearch,0)
strText = Mid(strText,stMatch+2,strLength)
IntCount = IntCount+1
Else
Exit For
End If
Next
FnMatchedStringCountFromText = IntCount
End Function