Garry's Mod Wiki

Revision Difference

utf8.codes#547805

<function name="codes" parent="utf8" type="libraryfunc"> <description>Returns an iterator (like <page>string.gmatch</page>) which returns both the position and codepoint of each utf8 character in the string. It raises an error if it meets any invalid byte sequence.</description> <realm>Shared</realm> <file line="141-L168">lua/includes/modules/utf8.lua</file> <file line="146-L173">lua/includes/modules/utf8.lua</file> <args> <arg name="string" type="string">The string that you will get the codes from.</arg> </args> <rets> <ret name="" type="function">The iterator (to be used in a for loop).</ret> </rets> </function> <example> <description>Demonstrates usage of the function.</description> <code> for p, c in utf8.codes("( ͡° ͜ʖ ͡°)") do print(p,c) end </code> <output> ``` 1 40 2 32 3 865 5 176 7 32 8 860 10 662 12 32 13 865 15 176 17 41 ``` </output> </example>