我需要計算字符串中的前導(dǎo)零。這是我發(fā)現(xiàn)的整數(shù)前導(dǎo)零計數(shù) static int LeadingZeros(int value){ // Shift right unsigned to work with both positive and negative values var uValue = (uint) value; int leadingZeros = 0; while(uValue != 0) { uValue = uValue >> 1; leadingZeros++; } return (32 - leadingZeros);}但找不到計算字符串中的前導(dǎo)零。string xx = "000123";上面的例子有 000 所以我想得到結(jié)果計數(shù)為 3我如何計算字符串中的零?如果有人給我小費(fèi)非常感謝
2 回答

搖曳的薔薇
TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個贊
最簡單的方法是使用 LINQ :
var text = "000123";
var count = text.TakeWhile(c => c == '0').Count();
- 2 回答
- 0 關(guān)注
- 151 瀏覽
添加回答
舉報
0/150
提交
取消