3

Possible Duplicate:
How would you count occurences of a string within a string (C#)?

I am reading a file in line by line and need to count the number of tabs that each string contains. How can I get a count of the tabs i.e. \t from the string.

Thanks for your help

Community
  • 1
  • 1
Boardy
  • 33,990
  • 95
  • 247
  • 427

1 Answers1

9
uint howManyTabs(string s) {
    return (uint)s.Count(ch => ch == '\t');
}
Brennan Vincent
  • 10,134
  • 9
  • 30
  • 52