How to count number of characters & words in array in C#?
For e.g.:
char[] arr= "My name is ABC XYZ".Tochararray();
should return 5 as number of words and 18 (space is counted as character) as number of characters.
Thanks!
You can't directly assign a string to an array of integers/chars in c#
string s = "My name is ABC XYZ";
int l = s.Length // 18 chars;
int w = s.Split(' ').Count(); // 5 words
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With