parseNumber: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(description)
(fix commit, added example)
Line 7: Line 7:
____________________________________________________________________________________________
____________________________________________________________________________________________


| Parses the string, interpreting its content as a floating point number. The command first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals, and interprets them as a numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this command. If the first sequence of non-whitespace characters in string does not form a valid floating-point number, or if no such sequence exists because either string is empty or contains only whitespace characters, no conversion is performed and the command returns 0. |= Description
| Parses the string, interpreting its content as a floating point number.
<br>The command first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals, and interprets them as a numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this command.
<br>If the first sequence of non-whitespace characters in string does not form a valid floating-point number, or if no such sequence exists because either string is empty or contains only whitespace characters, no conversion is performed and the command returns 0. |= Description
____________________________________________________________________________________________
____________________________________________________________________________________________


| [[Number]] <nowiki>=</nowiki> '''parseNumber''' string |= Syntax
| '''parseNumber''' string |= Syntax


|p1= string: [[String]] |= Parameter 1
|p1= string: [[String]] |= Parameter 1
Line 17: Line 19:
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= _number <nowiki>=</nowiki> '''parseNumber''' "0.125" |= Example 1
|x1= <code>_number = [[parseNumber]] "0.125";</code> |= Example 1
 
|x2= <code>_number = [[parseNumber]] "2 abc";//2</code> |= Example 2
____________________________________________________________________________________________
____________________________________________________________________________________________


| |= See also
| [[BIS_fnc_parseNumber]] |= See also


}}
}}
Line 27: Line 31:
<dl class="command_description">
<dl class="command_description">
<!-- Note Section BEGIN -->
<!-- Note Section BEGIN -->
* If the text does not represent a number ("abc" for example), parseNumber will return 0 (zero). It is therefore not possible to use parseNumber to determine if the string contains a valid number or not.
<dd class="notedate">Posted on Aug 28, 2014
<strong>I beg to differ.</strong><br />
<dt class="note">[[User:ffur2007slx2_5|ffur2007slx2_5]]
_stringNotContainingValidNumber = "abc";
<dd class="note"> (A3 1.26)It only detects the first occurrence of a number in the string, return 0 by default.
if(parseNumber _stringNotContainingValidNumber == 0 && _stringNotContainingValidNumber != "0") then
<code>[[parseNumber]] "2s4f"; // 2
{
[[parseNumber]] "s2f4"; // 0</code>
    comment "INVALID NUMBER";
parse config or code, currently [[BIS_fnc_parseNumber]], occurrence is only limited with number, return -1 by default.
}
<code>{s3s4f} [[call]] [[BIS_fnc_parseNumber]]; // -1</code>
else
{
    comment "VALID NUMBER";
};
[[User:MulleDK13|MulleDK13]] 09:26, 11 July 2010 (CEST)
<!-- Note Section END -->
<!-- Note Section END -->
</dl>
</dl>
Line 47: Line 46:
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands VBS2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]

Revision as of 00:38, 3 October 2014

-wrong parameter ("Arma") defined!-1.00
Hover & click on the images for description

Description

Description:
Parses the string, interpreting its content as a floating point number.
The command first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals, and interprets them as a numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this command.
If the first sequence of non-whitespace characters in string does not form a valid floating-point number, or if no such sequence exists because either string is empty or contains only whitespace characters, no conversion is performed and the command returns 0.
Groups:
Uncategorised

Syntax

Syntax:
parseNumber string
Parameters:
string: String
Return Value:
Number

Examples

Example 1:
_number = parseNumber "0.125";
Example 2:
_number = parseNumber "2 abc";//2

Additional Information

See also:
BIS_fnc_parseNumber

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

Notes

Posted on Aug 28, 2014
ffur2007slx2_5
(A3 1.26)It only detects the first occurrence of a number in the string, return 0 by default. parseNumber "2s4f"; // 2 parseNumber "s2f4"; // 0 parse config or code, currently BIS_fnc_parseNumber, occurrence is only limited with number, return -1 by default. {s3s4f} call BIS_fnc_parseNumber; // -1

Bottom Section