Skip to content

String unpacking

Adam edited this page Apr 14, 2019 · 2 revisions

Now that format and most of the other functions now return packed strings for efficiency reasons, unpacking them is also very easy to do so.

Let’s say your code looks like this:

#define function%0(%1) forward%0(%1); public%0(%1)

#include <string>
native format(output[], const format[], ...);

function OnFilterScriptInit() {
    new str[1];
    format(str, "%s", "Austinz"); // returns a packed string
    printf("%s, length: %d\n", str, sizeof(str))
    // output: Austinz, length: 1

    new str2[7 + 1] // +1 for '/t'
    strunpack(str2, str, sizeof(str2))
    printf("%s, length: %d\n", str2, sizeof(str2))
    // output: Austinz, length: 8

    return 1;
}
Clone this wiki locally