parseText: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(see also, note removed. Html tags are stripped by localize command not parseText, see note on localize page for a workaround)
m (Text replacement - "AgentRevolution" to "AgentRev")
 
(70 intermediate revisions by 7 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. Do not use parseText when displaying a localized text from stringtable.xml (see notes below). |= 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= <code>_Stxt = [[parseText]] "First line<img image='data\isniper.paa'/><nowiki><br/></nowiki>Second line";</code> |= Example 1


|x2= <code>[[hintSilent]] [[parseText]] [[format]]["<t size='1.25' font='Zeppelin33' color='#ff0000'>%1 lives remaining.</t>", 12];</code> |= Example 2
|gr1= Strings


|x3= <code>_clickableLink = [[parseText]] <nowiki>"<a href='http://arma3.com'>A3</a></nowiki>";</code> |= Example 3
|gr2= Structured Text
____________________________________________________________________________________________


| [[Structured Text]], [[composeText]], [[text]], [[localize]], [[ctrlSetStructuredText]] |= See also
|descr= Creates a structured text by parsing the given XML description. Do not use [[parseText]] when displaying a localized text from [[Stringtable.xml]].<br>
A detailed explanation of all formatting possibilities can be found at [[Structured Text]].


|s1= [[parseText]] text
|p1= text: [[String]]
|r1= [[Structured Text]]
|x1= <sqf>private _Stxt = parseText "First line<img image='data\isniper.paa'/><br/>Second line";</sqf>
|x2= <sqf>hintSilent parseText format["<t size='1.25' font='Zeppelin33' color='#ff0000'>%1 lives remaining.</t>", 12];</sqf>
|x3= <sqf>private _clickableLink = parseText "<a href='http://arma3.com'>A3</a>";</sqf>
|seealso= [[Structured Text]] [[composeText]] [[text]] [[localize]] [[ctrlSetStructuredText]]
}}
}}


<h3 style="display:none">Notes</h3>
 
<dl class="command_description">
<dl class="command_description">


<!-- Note Section BEGIN -->
<dd class="notedate">Posted on 1 September 2016</dd>
<dt class="note">[[User:Dr_Eyeball|Dr_Eyeball]]</dt>
<dd class="note">To convert a structured text back to a string type, just use:
<sqf>_str = str parseText _structuredText;</sqf>
 
<dt></dt>
<dd class="notedate">Posted on 2017-09-01 - 13:23 (UTC)</dd>
<dt class="note">[[User:AgentRev|AgentRev]]</dt>
<dd class="note">
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;"]
};


<dd class="notedate">Posted on 22:07, 11 May 2007 (CEST)
private _name = '<A&M> Paul "Bear" Bryant';
<dt class="note>'''[[User:Mondkalb|Mondkalb]]''', '''[[User:Spinor|Spinor]]''', '''[[User:HeliJunkie|HeliJunkie]]'''
private _escapedName = _name call _escapeXML;
<dd class="note">You can also colorate your text. You just have to use following tag:
private _redName = parseText format ["<t color='#ff0000'>%1</t>", _escapedName];</sqf>
<pre> <t color='#ffff00'>Your yellow text!</t> </pre>
</dd>
To change the size of your text, use this command:
<pre> <t size='2.2'>Your bigger text!</t> </pre>
To change text font, use:
<pre> <t font='Zeppelin33'>Bold Text</t> </pre>
To change horizontal alignment, use (parameter can be 'left', 'center', 'right'):
<pre> <t align='center'>Centered Text</t> </pre>
To change vertical alignment within a line, use (parameter can be 'top', 'middle', 'bottom'):
<pre> <t valign='bottom'>Text at Line Bottom</t> </pre>
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>
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>


<dd class="notedate">Posted on 21 March 2009
<dt class="note>'''[[User:Spooner|Spooner]]'''
<dd class="note">Although there is a dedicated [[image]] command, [[parseText]] gives more options:
<pre><img size='5' color='#ff0000' image='fish.paa'/></pre>
<!-- Note Section END -->
</dl>
</dl>


<h3 style="display:none">Bottom Section</h3>
{{Note
[[Category:Scripting Commands|PARSETEXT]]
|user= Samatra
[[Category:Scripting Commands OFP Elite |PARSETEXT]]
|timestamp= 20231013120233
[[Category:Scripting Commands ArmA|PARSETEXT]]
|text= Here is a useful script snippet to safely use angled braces and ampersand in structured texts:
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
<sqf>_string  regexReplace ["&", "&amp;"] regexReplace ["<", "&lt;"]</sqf>
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
}}
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]

Latest revision as of 00:07, 5 May 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


Posted on 1 September 2016
Dr_Eyeball
To convert a structured text back to a string type, just use:
_str = str parseText _structuredText;
Posted on 2017-09-01 - 13:23 (UTC)
AgentRev
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];
Samatra - 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;"]