Logo

Programming-Idioms

Set b to true if the byte sequence s consists entirely of valid UTF-8 character code points, false otherwise.
New implementation

Type ahead, or select one

Explain stuff

To emphasize a name: _x → x

Please be fair if you are using someone's work

You agree to publish under the CC-BY-SA License

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
using System.Text;
var encoding = new UTF8Encoding(false, true);
bool b;
try
{
    encoding.GetCharCount(s);
    b = true;
}
catch (DecoderFallbackException)
{
    b = false;
}

.NET encodings use replacement fallback by default; exception fallback can be specified using the UTF8Encoding constructor.