Vb.net 获取字符串中字符的计数
如何计算VB.NET中字符串中出现的特定字符数?Vb.net 获取字符串中字符的计数,vb.net,string,Vb.net,String,如何计算VB.NET中字符串中出现的特定字符数? 例如,我有一个字符串: 123#17453#40110#065 我想确定获取#符号计数的代码是什么 这是详细的VB.NET示例: Dim s As String = "123#17453#40110#065" Dim count As Integer = 0 For Each c As Char In s If c = "#" Then count = count + 1 Next Console.WriteLine("'#' appea
例如,我有一个字符串: 123#17453#40110#065 我想确定获取
#
符号计数的代码是什么
这是详细的VB.NET示例:
Dim s As String = "123#17453#40110#065"
Dim count As Integer = 0
For Each c As Char In s
If c = "#" Then count = count + 1
Next
Console.WriteLine("'#' appears {0} times.", count)
强制性最低限度C#示例:
下面是一个lambda表达式:
Dim s As String = "123#17453#40110#065"
Dim result = s.Where(Function(c) c = "#"c).Count
试试这个:
Dim count = "123.0#17453#40110#065".Count(Function(x) x = "#")
或通过模块中的扩展方法:
<Extension> Public Function Occurs(target As String, character As Char) As Integer
Return target.Count(Function(c) c = character)
End Function
Dim count = "123.0#17453#40110#065".Occurs("#"c)
公共函数以整数形式出现(目标为字符串,字符为字符)
返回target.Count(函数(c)c=字符)
端函数
Dim count=“123.0#17453#40110#065”。发生(#c)
<Extension> Public Function Occurs(target As String, character As Char) As Integer
Return target.Count(Function(c) c = character)
End Function
Dim count = "123.0#17453#40110#065".Occurs("#"c)