字符串中的字符出现的次数 [英] Number of occurrences of a character in a string
本文介绍了字符串中的字符出现的次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得某个字符的出现次数,例如&放大器;
以下字符串
I am trying to get the number of occurrences of a certain character such as &
in the following string.
string test = "key1=value1&key2=value2&key3=value3";
我如何确定有2个符号(&安培;)?在上面的测试字符串变量
How do I determine that there are 2 ampersands (&) in the above test string variable?
推荐答案
您可以这样做:
int count = test.Split('&').Length - 1;
或者使用LINQ:
test.Count(x => x == '&');
这篇关于字符串中的字符出现的次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文