# How fast can you fix a UTF-16 string in C#?

DevFeed: [How fast can you fix a UTF-16 string in C#?](<https://devfeed.tech/articles/how-fast-can-you-fix-a-utf-16-string-in-c-60465.md>)

Original publisher: [Read original article](<https://lemire.me/blog/2026/09/26/how-fast-can-you-fix-a-utf-16-string-in-c/>)

Author: Daniel Lemire

Published: 2026-09-26T16:53:53Z

Content type: article

Language: en

Sources: [Daniel Lemire](<https://devfeed.tech/sources/daniel-lemire.md>)

Topics: [Encoding](<https://devfeed.tech/topics/encoding.md>), [version](<https://devfeed.tech/topics/version.md>), [Python](<https://devfeed.tech/topics/python.md>)

Tags: [avx](<https://devfeed.tech/tags/avx.md>), [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [chips](<https://devfeed.tech/tags/chips.md>), [code](<https://devfeed.tech/tags/code.md>), [intel](<https://devfeed.tech/tags/intel.md>), [intel-xeon](<https://devfeed.tech/tags/intel-xeon.md>), [linux](<https://devfeed.tech/tags/linux.md>), [macos](<https://devfeed.tech/tags/macos.md>), [parallelism](<https://devfeed.tech/tags/parallelism.md>), [performance](<https://devfeed.tech/tags/performance.md>)

## AI overview

The article describes SIMD-based C# functions in the SimdUnicode library that repair ill-formed UTF-16 strings by replacing lone surrogates with U+FFFD and validate strings for such surrogates. It reports throughput comparisons on an Intel Xeon and Apple M4 Max, including that repair of well-formed strings is roughly as fast as a memory copy.

## Source excerpt

C# strings are UTF-16. Most characters are one 16-bit code unit. Characters outside the basic multilingual plane, emoji included, take two: a high surrogate (U+D800 to U+DBFF) followed by a low surrogate (U+DC00 to U+DFFF). A surrogate with the wrong neighbor, or with none, is ill-formed. You should never send an ill-formed string to disk ... Continue reading How fast can you fix a UTF-16 string in C#?