使用一個單重的循環(huán)掃描這個字符串中的所有字符,對每一個字符的出現(xiàn)次數(shù)進(jìn)行統(tǒng)計(jì),最后輸出每個字符的出現(xiàn)次數(shù)。
成都創(chuàng)新互聯(lián)公司于2013年開始,先為塔城等服務(wù)建站,塔城等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為塔城企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
Private Sub Command1_Click()
s = InputBox("請輸入一個英文字符串:")
Dim a(128) As Integer
For i = 1 To Len(s)
t = Asc(Mid(s, i, 1))
a(t) = a(t) + 1
Next i
For i = 1 To 127
If a(i) 0 Then Print Chr(i); ":"; a(i)
Next i
End Sub
調(diào)用 腳本解析引擎,
textbox2.text=Eval(textbox1.text).ToString()
Function?Eval(ByVal?Expressions?As?String)?As?Double
Dim?Mssc?=?CreateObject("MSScriptControl.ScriptControl")
Mssc.Language?=?"vbscript"
Return?CDbl(?Mssc.Eval(Expressions))
End?Function
不喜歡上面提示的警告的話
textbox2.text=EvalString(textbox1.text)
Function?EvalString(ByVal?Expressions?As?String)?As?String
dim?oType?=?System.Type.GetTypeFromProgID("MSScriptControl.ScriptControl")
Dim?o?=?System.Activator.CreateInstance(oType)
oType.InvokeMember("Language",?System.Reflection.BindingFlags.SetProperty?,?Nothing,?o,New?Object(){?"vbscript"})
Return?oType.InvokeMember("Eval",?System.Reflection.BindingFlags.InvokeMethod,?Nothing,?o,?New?Object(){Expressions}).ToString()
End?Function
Eval 在VB中使用,剛找到的_vb吧_百度貼吧
Dim str1 As String = "112113114111"
Dim str2 As String = "11"
Dim count As Integer = 0
For i As Integer = 0 To str1.Length - 1
Dim f As Integer = str1.IndexOf(str2, i)
If f -1 Then
MsgBox("str2出現(xiàn)在str1的" f "個字符位置")
i = f
count += 1
End If
Next
MsgBox("統(tǒng)計(jì)出str1中共有" count "個str2!")