I want to get the number of bytes in an arbitrary string. I can do it this way:
import 'dart:convert';
void main() {
String str = '你好';
final bytes = utf8.encode(str);
print(str.length); // 2
print(bytes.length); // 6
}
But is there a more direct way to do it that doesn't involve doing a conversion?