{"name":"parseText","operator":null,"title":"parseText","type":"command","url":"https://community.bistudio.com/wiki/parseText","revid":364995,"updated":"2024-07-04T19:58:06Z","groups":["Strings","Structured Text"],"status":"ok","replaced_by":[],"games":[{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Creates a structured text by parsing the given XML description. Do not use parseText when displaying a localized text from Stringtable.xml.\n\nA detailed explanation of all formatting possibilities can be found at Structured Text.","syntaxes":[{"syntax":"parseText text","since":null,"effect":null,"exec":null,"params":[{"name":"text","type":"String","optional":false,"default":null,"description":null,"types":["String"],"since":null,"text":"text: String"}],"returns":{"type":"Structured Text","types":["Structured Text"],"description":null,"text":"Structured Text"},"form":"unary","operator":null,"left":null,"right":{"text":"text","types":["String"]}}],"examples":[{"text":"```sqf\nprivate _Stxt = parseText \"First line<img image='data\\isniper.paa'/><br/>Second line\";\n```","code":["private _Stxt = parseText \"First line<img image='data\\isniper.paa'/><br/>Second line\";"]},{"text":"```sqf\nhintSilent parseText format[\"<t size='1.25' font='Zeppelin33' color='#ff0000'>%1 lives remaining.</t>\", 12];\n```","code":["hintSilent parseText format[\"<t size='1.25' font='Zeppelin33' color='#ff0000'>%1 lives remaining.</t>\", 12];"]},{"text":"```sqf\nprivate _clickableLink = parseText \"<a href='http://arma3.com'>A3</a>\";\n```","code":["private _clickableLink = parseText \"<a href='http://arma3.com'>A3</a>\";"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["Structured Text","composeText","text","localize","ctrlSetStructuredText"],"notes":[{"user":"Dr_Eyeball","date":"2016-09-01T06:47:00Z","text":"To convert a structured text back to a string type, just use:\n\n```sqf\n_str = str parseText _structuredText;\n```"},{"user":"AgentRev","date":"2017-09-01T13:23:00Z","text":"If you are parsing user-defined strings like player names, you may want to convert special characters to their [XML entities](https://en.wikipedia.org/wiki/Character_encodings_in_HTML#XML_character_references) as a precaution beforehand, otherwise the result might be corrupted.\n\n```sqf\nprivate _escapeXML =\n{\n    _this\n    regexReplace [\"&\", \"&\"]\n    regexReplace [\"<\", \"<\"]\n    regexReplace [\">\", \">\"]\n    regexReplace ['\"', \"\"\"]\n    regexReplace [\"'\", \"'\"]\n};\n\nprivate _name = '<A&M> Paul \"Bear\" Bryant';\nprivate _escapedName = _name call _escapeXML;\nprivate _redName = parseText format [\"<t color='#ff0000'>%1</t>\", _escapedName];\n```"},{"user":"Sa-Matra","date":"2023-10-13T12:02:33Z","text":"Here is a useful script snippet to safely use angled braces and ampersand in structured texts:\n\n```sqf\n_string regexReplace [\"&\", \"&\"] regexReplace [\"<\", \"<\"]\n```"}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Strings","Command Group: Structured Text","Introduced with Operation Flashpoint: Elite version 1.00","Operation Flashpoint: Elite: New Scripting Commands","Operation Flashpoint: Elite: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}