What does the .NET String.Length property return? Surrogate neutral length or complete character length

后端 未结 3 1967
悲哀的现实
悲哀的现实 2020-12-14 01:56

The documentation and language varies between VS 2008 and 2010:


VS 2008 Documentation

Internally, the text is stored as a read

3条回答
  •  难免孤独
    2020-12-14 02:17

    String.Length does not account for surrogate pairs, it only counts UTF-16 chars (i.e. chars are always 2 bytes) - surrogate pairs are counted as 2 chars.

提交回复
热议问题