可能重複:
Count specific character occurances in string計算字符串中char的出現次數?
我在字符串中的分隔符,我要驗證。我如何計算該字符的出現次數。現在我有下一個功能。
Private Shared Function CountChars(ByVal value As String) As Integer
Dim count = 0
For Each c As Char In value
If c = "$"c Then
count += 1
End If
Next
Return count
End Function
任何替代解決方案看起來更好?
http://stackoverflow.com/questions/5193893/count-specific-字符發生在字符串中有你的答案 – Marco 2012-03-30 07:44:44
你的代碼是好的:)也許通過指定char作爲參數來通用。 – Bas 2012-03-30 07:48:39