C# 字符串中计算 '1' 的数量
可以使用以下代码来计算一个字符串中包含 '1' 的数量:
string str = '1010101';
int count = 0;
foreach(char c in str)
{
if(c == '1')
{
count++;
}
}
Console.WriteLine('字符串中包含 {0} 个1。', count);
输出:
字符串中包含 4 个1。
原文地址: https://www.cveoy.top/t/topic/oQcG 著作权归作者所有。请勿转载和采集!