Wednesday, December 22, 2021

c# - How to quickly get count of the char in string

The fastest way in c# (counts the commas here):
string s = "Added on Monday, December 20, 2021 2:19:21 PM";
int count = note.Location.Count( x => x == ',' );
Output:
2

No comments:

Post a Comment