{"name":"parseText","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","games":{"ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofpe 1.00","arma3_since":"0.50","description":"Creates a structured text by parsing the given XML description. Do not use parseText when displaying a localized text from Stringtable.xml.\nA detailed explanation of all formatting possibilities can be found at Structured Text.","syntaxes":[{"syntax":"parseText text","params":[{"name":"text","type":"String","type_expr":"String"}],"returns":{"type":"Structured Text","type_expr":"Structured Text"},"form":"unary","right":{"text":"text"}}],"examples":[{"code":["private _Stxt = parseText \"First line<img image='data\\isniper.paa'/><br/>Second line\";"]},{"code":["hintSilent parseText format[\"<t size='1.25' font='Zeppelin33' color='#ff0000'>%1 lives remaining.</t>\", 12];"]},{"code":["private _clickableLink = parseText \"<a href='http://arma3.com'>A3</a>\";"]}],"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 [\"&\", \"&amp;\"]\n    regexReplace [\"<\", \"&lt;\"]\n    regexReplace [\">\", \"&gt;\"]\n    regexReplace ['\"', \"&quot;\"]\n    regexReplace [\"'\", \"&apos;\"]\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 [\"&\", \"&amp;\"] regexReplace [\"<\", \"&lt;\"]\n```"}]}