does any of you know what would be better:
a. get a string s, convert to char array and loop over it, or
b. get a string s, loop over substrings of it (s.Substring(i, 1))?
Any tips much appreciated.
Option b), looping over substrings, is very inefficient.
The fastest method would be
c) loop over the string chars directly, using the read-only indexer property:
for (int i = 0; i < s.Length; i++) { char c = s[i]; ... }
or, based on the IEnumerable<char> interface:
foreach(char c in s) { ... }
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