Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #287 Number of bytes of a string

Assign to n the number of bytes in the string s.

This can be different from the number of characters. If n includes more bytes than the characters per se (trailing zero, length field, etc.) then explain it. One byte is 8 bits.

import 'dart:convert';
var n = utf8.encode(s).length;

New implementation...