Search code examples
stringwinapiunicodeutf-16

Win32 UTF-16 character indexing


I'm just starting out with Win32 unicode strings (UTF-16). Is there any way to quickly obtain the byte index of any particular character in the string, since some characters might use four bytes (from what I gather reading MSDN)? Or should they all be considered two bytes per character?


Solution

  • The CharNext() and CharPrev() APIs can be used to safely walk UNICODE strings on Windows.

    To obtain the nth character of a UNICODE string, call CharNext() in a loop.