parseText: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Added info that images can be coloured and resized.)
m (Text replacement - "Samatra" to "Sa-Matra")
 
(87 intermediate revisions by 15 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma |= Game name
|game1= ofpe
|version1= 1.00


|1.00|= Game version
|game2= arma1
____________________________________________________________________________________________
|version2= 1.00


| Creates a structured text by parsing the given XML description. |= Description
|game3= arma2
____________________________________________________________________________________________
|version3= 1.00


| [[Structured Text]] <nowiki>=</nowiki> '''parseText''' text |= Syntax
|game4= arma2oa
|version4= 1.50


|p1= text: [[String]] |= Parameter 1
|game5= tkoh
|version5= 1.00


| [[Structured Text]] |= Return value
|game6= arma3
____________________________________________________________________________________________
|version6= 0.50
 
|x1= <pre>_Stxt = parseText "First line<img image='data\isniper.paa'/><br/>Second line"</pre> |= Example 1
____________________________________________________________________________________________


| |= See also
|gr1= Strings


}}
|gr2= Structured Text


<h3 style="display:none">Notes</h3>
|descr= Creates a structured text by parsing the given XML description. Do not use [[parseText]] when displaying a localized text from [[Stringtable.xml]].<br>
<dl class="command_description">
A detailed explanation of all formatting possibilities can be found at [[Structured Text]].
<!-- Note Section BEGIN -->
--[[User:Spooner|Spooner]] 21 March 2009


Although there is a dedicated [[image]] command, [[parseText]] gives more options:
|s1= [[parseText]] text
<pre><img size='5' color='#ff0000' image='fish.paa'></pre>


--[[User:Mondkalb|Mondkalb]] 22:07, 11 May 2007 (CEST)
|p1= text: [[String]]


You can also colorate your text. You just have to use following tag:
|r1= [[Structured Text]]


<pre> <t color='#ffff00'>Your yellow text!</t> </pre>
|x1= <sqf>private _Stxt = parseText "First line<img image='data\isniper.paa'/><br/>Second line";</sqf>


To change the size of your text, use this command:
|x2= <sqf>hintSilent parseText format["<t size='1.25' font='Zeppelin33' color='#ff0000'>%1 lives remaining.</t>", 12];</sqf>


<pre> <t size='2.2'>Your bigger text!</t> </pre>
|x3= <sqf>private _clickableLink = parseText "<a href='http://arma3.com'>A3</a>";</sqf>


--[[User:Spinor|Spinor]]
|seealso= [[Structured Text]] [[composeText]] [[text]] [[localize]] [[ctrlSetStructuredText]]
}}


To change text font, use:
{{Note
|user= Dr_Eyeball
|timestamp= 20160901064700
|text= To convert a structured text back to a string type, just use:
<sqf>_str = str parseText _structuredText;</sqf>
}}


<pre> <t font='Zeppelin33'>Bold Text</t> </pre>
{{Note
|user= AgentRev
|timestamp= 20170901132300
|text= If you are parsing user-defined strings like player names, you may want to convert special characters to their {{Link|https://en.wikipedia.org/wiki/Character_encodings_in_HTML#XML_character_references|XML entities}} as a precaution beforehand, otherwise the result might be corrupted.
<sqf>
private _escapeXML =
{
_this
regexReplace ["&", "&amp;"]
regexReplace ["<", "&lt;"]
regexReplace [">", "&gt;"]
regexReplace ['"', "&quot;"]
regexReplace ["'", "&apos;"]
};


To change horizontal alignment, use (parameter can be 'left', 'center', 'right'):
private _name = '<A&M> Paul "Bear" Bryant';
private _escapedName = _name call _escapeXML;
private _redName = parseText format ["<t color='#ff0000'>%1</t>", _escapedName];
</sqf>
}}


<pre> <t align='center'>Centered Text</t> </pre>
{{Note
 
|user= Sa-Matra
To change vertical alignment within a line, use (parameter can be 'top', 'middle', 'bottom'):
|timestamp= 20231013120233
 
|text= Here is a useful script snippet to safely use angled braces and ampersand in structured texts:
<pre> <t valign='bottom'>Text at Line Bottom</t> </pre>
<sqf>_string regexReplace ["&", "&amp;"] regexReplace ["<", "&lt;"]</sqf>
 
}}
To underline text, use:
 
<pre> <t underline='true'>Underlined Text</t> </pre>
 
To put shadow under text, use:
 
<pre> <t shadow='true'><t shadowColor='#ff0000'>Text with Red Shadow</t></t> </pre>
 
--[[User:HeliJunkie|HeliJunkie]]
 
Following statements are valid too:
<pre><t underline='1'>Underlined Text</t>
<t shadow='1'shadowColor='#ff0000'>Green shadow text</t>
</pre>
 
Following fonts are valid (got from config):
<pre><t font='Zeppelin32'>Zeppelin32 (normal text)</t>
<t font='Zeppelin33'>Zeppelin33 (bold text)</t>
<t font='Zeppelin33Italic'>Zeppelin33Italic (bold italic text)</t>
<t font='Bitstream'>Bitstream (same as Zeppelin32)</t>
<t font='TahomaB'>TahomaB (same as Zeppelin32)</t>
<t font='LucidaConsoleB'>LucidaConsoleB (like Courier)</t>
</pre>
 
<!-- Note Section END -->
</dl>
 
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands|PARSETEXT]]
[[Category:Scripting Commands OFP Elite |PARSETEXT]]
[[Category:Scripting Commands ArmA|PARSETEXT]]
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]

Latest revision as of 20:58, 4 July 2024

Hover & click on the images for description

Description

Description:
Creates a structured text by parsing the given XML description. Do not use parseText when displaying a localized text from Stringtable.xml.
A detailed explanation of all formatting possibilities can be found at Structured Text.
Groups:
StringsStructured Text

Syntax

Syntax:
parseText text
Parameters:
text: String
Return Value:
Structured Text

Examples

Example 1:
private _Stxt = parseText "First line<img image='data\isniper.paa'/><br/>Second line";
Example 2:
hintSilent parseText format["<t size='1.25' font='Zeppelin33' color='#ff0000'>%1 lives remaining.</t>", 12];
Example 3:
private _clickableLink = parseText "<a href='http://arma3.com'>A3</a>";

Additional Information

See also:
Structured Text composeText text localize ctrlSetStructuredText

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Dr_Eyeball - c
Posted on Sep 01, 2016 - 06:47 (UTC)
To convert a structured text back to a string type, just use:
_str = str parseText _structuredText;
AgentRev - c
Posted on Sep 01, 2017 - 13:23 (UTC)
If you are parsing user-defined strings like player names, you may want to convert special characters to their XML entities as a precaution beforehand, otherwise the result might be corrupted.
private _escapeXML = { _this regexReplace ["&", "&amp;"] regexReplace ["<", "&lt;"] regexReplace [">", "&gt;"] regexReplace ['"', "&quot;"] regexReplace ["'", "&apos;"] }; private _name = '<A&M> Paul "Bear" Bryant'; private _escapedName = _name call _escapeXML; private _redName = parseText format ["<t color='#ff0000'>%1</t>", _escapedName];
Sa-Matra - c
Posted on Oct 13, 2023 - 12:02 (UTC)
Here is a useful script snippet to safely use angled braces and ampersand in structured texts:
_string regexReplace ["&", "&amp;"] regexReplace ["<", "&lt;"]