Strings and StringBuilder

Use UTF-8 Sharp Runtime text APIs without assuming .NET UTF-16 indexing.

IntermediateTutorial

Know the representation

Sharp Runtime’s common string surface is based on UTF-8 std::string. That is excellent for native interoperability but differs from .NET’s UTF-16 System.String.

StringBuilder byte positions

Current StringBuilder length, index and count operations use UTF-8 storage bytes. For example, éA occupies three bytes even though a user sees two characters. An index-taking mutation can split a multi-byte scalar.

Practical guidance

  • Use append and whole-string operations when byte indexing is irrelevant.
  • Use rune/scalar-aware iteration for Unicode code points.
  • Do not use byte length as a display-column or grapheme count.
  • Test malformed input and culture-sensitive formatting separately.
Not UTF-16 parity

Code ported from C# that stores string indices or slices arbitrary text needs a deliberate unit conversion; a mechanical method rename is insufficient.