toString: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " *\| *([Cc]omments|COMMENTS|Game|[Gg]ame [Nn]ame( +[0-9])?|Game [Vv]ersion( +[0-9])?|Game Version \(number surrounded by NO SPACES\)|Arguments in MP|MP[Aa]rg|Multiplayer Arguments( \("local" or "global"\))?|Effects|Execution|Effects...)
m (Add parseSimpleArray link)
 
(59 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Command
{{RV|type=command


| arma1
|game1= arma1
|version1= 1.09


|1.09
|game2= arma2
|version2= 1.00
 
|game3= arma2oa
|version3= 1.50
 
|game4= tkoh
|version4= 1.00
 
|game5= arma3
|version5= 0.50


|gr1= Strings
|gr1= Strings
Line 9: Line 20:
|gr2= Arrays
|gr2= Arrays


| Converts the supplied [[Array]] of [[Number|Numbers]] into a [[String]]. <br>
|descr= Converts the supplied [[Array]] of [[Number]]s into a [[String]] through {{Link|https://en.wikipedia.org/wiki/Unicode}} characters representation conversion, or provided [[Code]] to [[compile|compilable]] [[String]].
The numbers in the array to be converted are the decimal [http://en.wikipedia.org/wiki/Unicode Unicode] representations of characters.
{{Warning | This command expects array of numbers. If array contains non-number values, the following error might appear in .rpt file: <tt>Bad conversion: scalar</tt>}}


|s1= [[toString]] array


|p1= array: [[Array]] of [[Number]]s
{{Feature|important|If ''array'' contains non-number values, the following error might appear in .rpt file: {{hl|Bad conversion: scalar}}. See [[parseSimpleArray]] for multi-type array.}}


|r1= [[String]] - {{Link|https://en.wikipedia.org/wiki/Unicode}} numbers converted to [[String]] of characters


| '''toString''' array
|s2= [[toString]] code


|p1= array: [[Array]]
|s2since= arma3 2.02


| [[String]]
|p21= code: [[Code]]


|x1= <code>[[hint]] [[toString]] [65,97,338];</code> returns "AaŒ"
|r2= [[String]] - [[compile|compilable]] [[String]] from provided code
|x2= <code>["test","test"] [[joinString]] [[toString]] [12345] [[splitString]] [[toString]] [12345]; // ["test","test"]</code>


| [[set]], [[resize]], [[reverse]], [[select]], [[in]], [[find]], [[toArray]], [[forEach]], [[count]], [[deleteAt]], [[deleteRange]], [[append]], [[sort]], [[param]], [[params]], [[arrayIntersect]], [[splitString]], [[joinString]], [[toLower]], [[toUpper]], [[toFixed]], [[endl]], [[format]], [[formatText]], [[toLowerANSI]], [[toUpperANSI]], [http://www.utf8-chartable.de/ Unicode Character Table]
|x1= <sqf>hint toString [65,97,338]; // returns "AaŒ"</sqf>


}}
|x2= <sqf>["test", "test"] joinString toString [12345] splitString toString [12345]; // ["test", "test"]</sqf>


<h3 style="display:none">Notes</h3>
|x3= <sqf>
<dl class="command_description">
private _compilableString = toString { hint "it works!" };
hint _compilableString; // hints ' hint "it works!" '
sleep 2;
call compile _compilableString; // hints ' it works! '
</sqf>


</dl>
|seealso= [[parseSimpleArray]] [[set]] [[resize]] [[reverse]] [[select]] [[in]] [[find]] [[toArray]] [[forEach]] [[count]] [[deleteAt]] [[deleteRange]] [[append]] [[sort]] [[param]] [[params]] [[arrayIntersect]] [[splitString]] [[joinString]] [[toLower]] [[toUpper]] [[toFixed]] [[endl]] [[format]] [[formatText]] [[toLowerANSI]] [[toUpperANSI]], {{Link|http://www.utf8-chartable.de/|Unicode Character Table}}
}}


[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
{{Note
{{GameCategory|arma1|Scripting Commands}}
|user= DreadedEntity
 
|timestamp= 20150210210500
{{GameCategory|arma2|Scripting Commands}}
|text= Tabs and new lines can be created with [[toString]] [9] and [[toString]] [10], respectively. Alternatively, a new line can also be created with [[toString]] [92,110] ("\n"). If you save these strings into a variable, they can be manipulated like any other string. For example, the following code will work just fine and return the expected output:
{{GameCategory|arma3|Scripting Commands}}
<sqf>
{{GameCategory|tkoh|Scripting Commands}}
_tab = toString [9];
 
for "_i" from 0 to 3 do
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on February 10, 2015 - 21:05 (UTC)</dd>
<dt class="note">[[User:DreadedEntity|DreadedEntity]]</dt>
<dd class="note">
Tabs and new lines can be created with [[toString]] [9] and [[toString]] [10], respectively. Alternatively, a new line can also be created with [[toString]] [92,110] ("\n"). If you save these strings into a variable, they can be manipulated like any other string. For example, the following code will work just fine and return the expected output:
<code>_tab = [[toString]] [9];
[[for]] "_i" [[from]] 0 [[to]] 3 [[do]]
{
{
_tab = _tab + ([[toString]] [9]);
_tab = _tab + (toString [9]);
};
};
[[copyToClipboard]] [[format]] ["x%1x",tab];</code>
copyToClipboard format ["x%1x",tab];
</dd>
</sqf>
</dl>
}}
<!-- DISCONTINUE Notes -->


<!-- CONTINUE Notes -->
{{Note
<dl class="command_description">
|user= Killzone_Kid
<dd class="notedate">Posted on August 25, 2015 - 09:58 (UTC)</dd>
|timestamp= 20150825095800
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
|text= While you can convert any [[String]] to [[Array]] with [[toArray]] command, only numbers from 1 to 55295 (not 65535 as expected) can be successfully converted to [[String]] with [[toString]] and then back to [[Array]] with [[toArray]] without loss of data.
<dd class="note">
}}
While you can convert any [[String]] to [[Array]] with [[toArray]] command, only numbers from 1 to 55295 (not 65535 as expected) can be successfully converted to [[String]] with [[toString]] and then back to [[Array]] with [[toArray]] without loss of data.
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 12:24, 6 December 2023

Hover & click on the images for description

Description

Description:
Converts the supplied Array of Numbers into a String through Unicode characters representation conversion, or provided Code to compilable String.
Groups:
StringsArrays

Syntax

Syntax:
toString array
Parameters:
array: Array of Numbers
If array contains non-number values, the following error might appear in .rpt file: Bad conversion: scalar. See parseSimpleArray for multi-type array.
Return Value:
String - Unicode numbers converted to String of characters

Alternative Syntax

Syntax:
toString code
Parameters:
code: Code
Return Value:
String - compilable String from provided code

Examples

Example 1:
hint toString [65,97,338]; // returns "AaŒ"
Example 2:
["test", "test"] joinString toString [12345] splitString toString [12345]; // ["test", "test"]
Example 3:
private _compilableString = toString { hint "it works!" }; hint _compilableString; // hints ' hint "it works!" ' sleep 2; call compile _compilableString; // hints ' it works! '

Additional Information

See also:
parseSimpleArray set resize reverse select in find toArray forEach count deleteAt deleteRange append sort param params arrayIntersect splitString joinString toLower toUpper toFixed endl format formatText toLowerANSI toUpperANSIUnicode Character Table

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
DreadedEntity - c
Posted on Feb 10, 2015 - 21:05 (UTC)
Tabs and new lines can be created with toString [9] and toString [10], respectively. Alternatively, a new line can also be created with toString [92,110] ("\n"). If you save these strings into a variable, they can be manipulated like any other string. For example, the following code will work just fine and return the expected output:
_tab = toString [9]; for "_i" from 0 to 3 do { _tab = _tab + (toString [9]); }; copyToClipboard format ["x%1x",tab];
Killzone_Kid - c
Posted on Aug 25, 2015 - 09:58 (UTC)
While you can convert any String to Array with toArray command, only numbers from 1 to 55295 (not 65535 as expected) can be successfully converted to String with toString and then back to Array with toArray without loss of data.