如何做在C strlen的计数单code [英] how does strlen count unicode in c

查看:186
本文介绍了如何做在C strlen的计数单code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,怎么算的strlen UNI code多字节字符C。

I'm curious as to how strlen count unicode characters of multiple bytes in C.

这是否算到每个字节或字符(因为它们可以由几个字节)第一个'\\ 0'?

Does it count each byte or character (as they can consist of several bytes) until first '\0'?

推荐答案

的strlen()计数,直到字节数 \\ 0 遇到。这适用于所有字符串如此。

strlen() counts number of bytes until a \0 is encountered. This holds true for all strings.

有关统一code,注意的返回值的strlen()可由可能存在的影响 \\ 0 在非空终止其他有效的字符字节。如果UTF-8时,这很好,因为ASCII以外没有任何有效的字符 0 可以有一个 \\ 0 字节但它可能不适用于其它编码真

For Unicode, note that the return value of strlen() may be affected by the possible existing \0 byte in a valid character other than the null terminator. If UTF-8 is used, it's fine because no valid character other than ASCII 0 can have a \0 byte, but it may not be true for other encodings.

这篇关于如何做在C strlen的计数单code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆