计算字符串中的选项卡数量

时间:2011-06-24 20:38:01

标签: c#

  

可能重复:
  How would you count occurences of a string within a string (C#)?

我正在逐行读取文件,需要计算每个字符串包含的标签数量。如何从字符串中获取选项卡的计数,即\ t。

感谢您的帮助

1 个答案:

答案 0 :(得分:8)

uint howManyTabs(string s) {
    return (uint)s.Count(ch => ch == '\t');
}