{"name":"String","title":"String","type":"topic","url":"https://community.bistudio.com/wiki/String","revid":373361,"updated":"2025-04-28T08:59:37Z","aliases":["Strings"],"markdown":"A **string** is a variable type that contains text. Possible length and characters depend on the game and its version.\n\n> [!NOTE]\n> The encoding should be mostly transparent. The input files can be encoded both in UTF-16 or UTF-8, the toString and toArray functions always convert from/to UTF-16 representation.\n\n### Properties\n\n|  | OFP | ArmA | Arma 2 | Arma 2:OA | Take On Helicopters | Arma 3 (before v1.56) | Arma 3 (since v1.56) |\n|---|---|---|---|---|---|---|---|\n| Max length | 2056 | No set limit | 9,999,999 to 10,000,000<br>(same as Array length) |  |  |  |  |\n| Encoding | [ASCII](https://en.wikipedia.org/wiki/ASCII) | [Unicode](https://en.wikipedia.org/wiki/Unicode) |  |  |  |  |  |\n| [Code page](https://en.wikipedia.org/wiki/Code_page) | product language defined | [UTF-8](https://en.wikipedia.org/wiki/UTF-8) |  |  |  |  |  |\n| \"text\" | ✓ |  |  |  |  |  |  |\n| 'text' | ✗ | ✓ |  |  |  |  |  |\n| {text} | ✓ | ✗ |  |  |  |  |  |\n\n### Commands and Functions\n\n- String Scripting Commands\n- String Functions\n\n### Single quote limitation\n\nStrings can be written with both double quotes (\"text\") and single quotes ('text'). While they are identical, there are slightly differences in how they are treated:\n- Single quote strings are parsed by the preprocessor and may cause undesired results.\n- Single quote strings do not seem to support tabs:\n\n```sqf\n_string = \"    \n    \";\ncopyToClipboard _string;\ndiag_log format [\"%1 %2 %3 x%4x\", toArray _string, toArray copyFromClipboard, toArray (_string select [0]), _string];\n\n/*\n    return is good: \"[9,10,9] [9,10,9] [9,10,9] x    \n    x\"\n*/\n```\n\n```sqf\n_string = '    \n    ';\ncopyToClipboard _string;\ndiag_log format [\"%1 %2 %3 x%4x\", toArray _string, toArray copyFromClipboard, toArray (_string select [0]), _string];\n\n/*\n    return: \"[9,10] [9,10] [9,10] x    \nx\" - second tab vanished\n*/\n```\n\nExample courtesy of [Rydygier](http://forums.bistudio.com/member.php?81568-Rydygier)\n\n### Examples\n\n#### Quotes in Quotes\n\n```sqf\nprivate _string = \"my string \"\"with\"\" quotes\";\nprivate _string = 'my string \"with\" quotes';\nprivate _string = 'my string with quotes';\n```\n\n#### String Formats\n\n```sqf\n// Operation Flashpoint\n_string = \"Hello there\" // works\n_string = 'Hello there' // does NOT work\n_string = {Hello there} // works\n```\n\n```sqf\n// since Armed Assault\n_string = \"Hello there\" // works\n_string = 'Hello there' // works\n_string = {Hello there} // does NOT work\n```\n\n#### Operators\n\n```sqf\nprivate _finalString = \"Hello\" + \" \" + \"there\"; // outputs \"Hello there\" - the + sign concatenates strings\n```\n\nThe only basic operator to be used on strings is \"plus\". You can use \"plus\" to concatenate two strings.\n\n#### Conversion\n\n```sqf\nprivate _value = 42; // this is a Number\nhint _value; // error - hint takes a String, not a Number\nhint format [\"%1\", _value]; // ok\nhint str _value; // ok - since Armed Assault\n```","sections":[{"heading":null,"level":1,"markdown":"A **string** is a variable type that contains text. Possible length and characters depend on the game and its version.\n\n> [!NOTE]\n> The encoding should be mostly transparent. The input files can be encoded both in UTF-16 or UTF-8, the toString and toArray functions always convert from/to UTF-16 representation."},{"heading":"Properties","level":3,"markdown":"|  | OFP | ArmA | Arma 2 | Arma 2:OA | Take On Helicopters | Arma 3 (before v1.56) | Arma 3 (since v1.56) |\n|---|---|---|---|---|---|---|---|\n| Max length | 2056 | No set limit | 9,999,999 to 10,000,000<br>(same as Array length) |  |  |  |  |\n| Encoding | [ASCII](https://en.wikipedia.org/wiki/ASCII) | [Unicode](https://en.wikipedia.org/wiki/Unicode) |  |  |  |  |  |\n| [Code page](https://en.wikipedia.org/wiki/Code_page) | product language defined | [UTF-8](https://en.wikipedia.org/wiki/UTF-8) |  |  |  |  |  |\n| \"text\" | ✓ |  |  |  |  |  |  |\n| 'text' | ✗ | ✓ |  |  |  |  |  |\n| {text} | ✓ | ✗ |  |  |  |  |  |"},{"heading":"Commands and Functions","level":3,"markdown":"- String Scripting Commands\n- String Functions"},{"heading":"Single quote limitation","level":3,"markdown":"Strings can be written with both double quotes (\"text\") and single quotes ('text'). While they are identical, there are slightly differences in how they are treated:\n- Single quote strings are parsed by the preprocessor and may cause undesired results.\n- Single quote strings do not seem to support tabs:\n\n```sqf\n_string = \"    \n    \";\ncopyToClipboard _string;\ndiag_log format [\"%1 %2 %3 x%4x\", toArray _string, toArray copyFromClipboard, toArray (_string select [0]), _string];\n\n/*\n    return is good: \"[9,10,9] [9,10,9] [9,10,9] x    \n    x\"\n*/\n```\n\n```sqf\n_string = '    \n    ';\ncopyToClipboard _string;\ndiag_log format [\"%1 %2 %3 x%4x\", toArray _string, toArray copyFromClipboard, toArray (_string select [0]), _string];\n\n/*\n    return: \"[9,10] [9,10] [9,10] x    \nx\" - second tab vanished\n*/\n```\n\nExample courtesy of [Rydygier](http://forums.bistudio.com/member.php?81568-Rydygier)"},{"heading":"Examples","level":3,"markdown":""},{"heading":"Quotes in Quotes","level":4,"markdown":"```sqf\nprivate _string = \"my string \"\"with\"\" quotes\";\nprivate _string = 'my string \"with\" quotes';\nprivate _string = 'my string with quotes';\n```"},{"heading":"String Formats","level":4,"markdown":"```sqf\n// Operation Flashpoint\n_string = \"Hello there\" // works\n_string = 'Hello there' // does NOT work\n_string = {Hello there} // works\n```\n\n```sqf\n// since Armed Assault\n_string = \"Hello there\" // works\n_string = 'Hello there' // works\n_string = {Hello there} // does NOT work\n```"},{"heading":"Operators","level":4,"markdown":"```sqf\nprivate _finalString = \"Hello\" + \" \" + \"there\"; // outputs \"Hello there\" - the + sign concatenates strings\n```\n\nThe only basic operator to be used on strings is \"plus\". You can use \"plus\" to concatenate two strings."},{"heading":"Conversion","level":4,"markdown":"```sqf\nprivate _value = 42; // this is a Number\nhint _value; // error - hint takes a String, not a Number\nhint format [\"%1\", _value]; // ok\nhint str _value; // ok - since Armed Assault\n```"}],"categories":["Data Types"],"groups":["Data Types"]}