str: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\|seealso= *\[\[([^ ]+)\]\], \[\[([^ ]+)\]\]" to "|seealso= $1 $2")
m (Some wiki formatting)
(26 intermediate revisions by the same user not shown)
Line 20: Line 20:
|descr= Converts any value into a string by placing " and " around the argument. When used on object, object debug name is returned.<br><br>Since Arma 3 v1.64 this command will correctly escape all " inside a string:
|descr= Converts any value into a string by placing " and " around the argument. When used on object, object debug name is returned.<br><br>Since Arma 3 v1.64 this command will correctly escape all " inside a string:


<code>{{cc|Before the fix:}}
<sqf>
[[hint]] [[str]] "string "" string"; {{cc|"string " string" <- invalid string}}
// Before the fix:
[[call]] [[compile]] [[str]] "string "" string"; {{cc|ERROR}}</code>
hint str "string "" string"; // "string " string" <- invalid string
call compile str "string "" string"; // ERROR
</sqf>


<code>{{cc|After the fix:}}
<sqf>
[[hint]] [[str]] "string "" string"; {{cc|"string "" string" <- valid string}}
// After the fix:
[[call]] [[compile]] [[str]] "string "" string"; {{cc|OK}}
hint str "string "" string"; // "string "" string" <- valid string
</code>
call compile str "string "" string"; // OK
</sqf>


|s1= [[str]] value
|s1= [[str]] value
Line 35: Line 38:
|r1= [[String]]
|r1= [[String]]


|x1= <code>_s = [[str]] (2 + 3);{{cc|The value of ''_s'' is the string "5"}}</code>
|x1= <sqf>_s = str (5 + 2); // The value of _s is the string "7"</sqf>


|x2= <code>a = [];
|x2= <sqf>
a = [];
ac = 0;
ac = 0;
[[while]] {ac < 5} [[do]]
while {ac < 5} do
{
{
ac = [[count]] a;
ac = count a;
a [[set]] [ac, [[format]] ["Index %1", ac]];
a set [ac, format ["Index %1", ac]];
};
};
[[hintSilent]] [[str]] a;{{cc|Hints all of ''["Index 0","Index 1","Index 2","Index 3","Index 4"]'' including brackets, quotes and commas}}</code>
hintSilent str a; // hints all of ["Index 0","Index 1","Index 2","Index 3","Index 4"] including brackets, quotes and commas
</sqf>


|seealso= [[toArray]] [[toString]], [[isText]], [[select]], [[count]], [[find]], [[endl]], [[format]], [[formatText]]
|seealso= [[toArray]] [[toString]] [[isText]] [[select]] [[count]] [[find]] [[endl]] [[format]] [[formatText]]
}}
}}


Line 70: Line 75:
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dd class="note">If you want to make empty string with [[str]] that doesn't have any quotation marks, but is still a [[String]] you can use [[text]]:  
<dd class="note">If you want to make empty string with [[str]] that doesn't have any quotation marks, but is still a [[String]] you can use [[text]]:  
<code>[[str]] ""; // ""
<sqf>str ""; // ""
[[count]] [[str]] ""; // 2
count str ""; // 2
[[str]] [[text]] ""; //
str text ""; //
[[count]] [[str]] [[text]] ""; // 0</code>
count str text ""; // 0</sqf>
</dd>
</dd>


Line 81: Line 86:
<dd class="note">
<dd class="note">
Be careful when using [[str]] on arrays and you are used to putting a ''whitespace'' behind every comma:
Be careful when using [[str]] on arrays and you are used to putting a ''whitespace'' behind every comma:
<code>[[str]] [0, 0, 0] {{=}}{{=}} "[0, 0, 0]"; {{cc|false}}</code>
<sqf>str [0, 0, 0] == "[0, 0, 0]"; // false</sqf>
</dd>
</dd>


</dl>
</dl>

Revision as of 14:59, 22 May 2022

Hover & click on the images for description

Description

Description:
Converts any value into a string by placing " and " around the argument. When used on object, object debug name is returned.

Since Arma 3 v1.64 this command will correctly escape all " inside a string:
// Before the fix: hint str "string "" string"; // "string " string" <- invalid string call compile str "string "" string"; // ERROR
// After the fix: hint str "string "" string"; // "string "" string" <- valid string call compile str "string "" string"; // OK
Groups:
Strings

Syntax

Syntax:
str value
Parameters:
value: Anything
Return Value:
String

Examples

Example 1:
_s = str (5 + 2); // The value of _s is the string "7"
Example 2:
a = []; ac = 0; while {ac < 5} do { ac = count a; a set [ac, format ["Index %1", ac]]; }; hintSilent str a; // hints all of ["Index 0","Index 1","Index 2","Index 3","Index 4"] including brackets, quotes and commas

Additional Information

See also:
toArray toString isText select count find endl format formatText

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 September 29, 2009 - 20:17 (UTC)
Sbsmac
When applied to a unit, this returns the variable name that was assigned to the unit in the editor. For example, if you have created a playable unit with the name 'thePlayer' then you can use 'str player' to return "thePlayer";
Posted on December 5, 2014 - 20:21 (UTC)
DreadedEntity
If you try to count string, the added quotations marks are valid characters and will be counted.
Posted on July 15, 2017 - 09:59 (UTC)
Killzone Kid
If you want to make empty string with str that doesn't have any quotation marks, but is still a String you can use text:
str ""; // "" count str ""; // 2 str text ""; // count str text ""; // 0
Posted on February 16, 2021 - 20:59 (UTC)
R3vo
Be careful when using str on arrays and you are used to putting a whitespace behind every comma:
str [0, 0, 0] == "[0, 0, 0]"; // false