开发者

how to get count of '#' in a string? [duplicate]

开发者 https://www.devze.com 2022-12-22 21:51 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: How would you count occurences of a str开发者_Python百科ing within a string (C#)?
This question already has answers here: Closed 10 years ago.

Possible Duplicate:

How would you count occurences of a str开发者_Python百科ing within a string (C#)?

how do I get the count of the occurrences of '#' in a string ?

something like int RowFormat = drr[3].ToString("#").Length;

example string "grtkj####mfr "

RowFormat must return 4

and yes ^_^ .NET 3.5


int RowFormat = "grtkj####mfr".Count(ch => ch == '#');


With LINQ (that's all the rage these days):

int RowFormat = drr[3].Count(x => x == '#');


Check this

"grtkj####mfr".Split(new char[]{'#'}).Length-1

hope that will help.


int RowFormat = new Regex("#").Matches("grtkj####mfr").Count;
0

精彩评论

暂无评论...
验证码 换一张
取 消