开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜