Storing a string as UTF8 in C#

前端 未结 4 735
忘了有多久
忘了有多久 2021-02-01 14:30

I\'m doing a lot of string manipulation in C#, and really need the strings to be stored one byte per character. This is because I need gigabytes of text simultaneously in memory

4条回答
  •  执念已碎
    2021-02-01 14:49

    As you've found, the CLR uses UTF-16 for character encoding. Your best bet may be to use the Encoding classes & a BitConverter to handle the text. This question has some good examples for converting between the two encodings:

    Convert String (UTF-16) to UTF-8 in C#

提交回复
热议问题