Difference between revisions of "StrToBool"

From SCAR Divi Manual
Jump to: navigation, search
(Undo revision 861 by Freddy (talk))
 
Line 1: Line 1:
 
==Definition==
 
==Definition==
 
<source lang="scar" lines="false">
 
<source lang="scar" lines="false">
function StrToFloat(s: string): Extended;
+
function StrToBool(Str: AnsiString): Boolean;
 
</source>
 
</source>
  
Line 8: Line 8:
  
 
==Description==
 
==Description==
Converts a given [[AnsiString|string]] '''s''' to an [[extended]] floating point value. If '''s''' is not a valid floating point value, the function throws an exception "Invalid float".
+
Converts a given [[AnsiString|string]] '''Str''' to a [[boolean]] value. If '''Str''' equals 'false' or '0', the result will be [false], if the '''Str''' is 'true' or a string representing any integer value that does not equal 0, the function returns [[true]]. In the event that '''Str''' is not a valid boolean value, the function will throw an exception.
  
 
==Example==
 
==Example==
 
<source lang="scar">
 
<source lang="scar">
 
begin
 
begin
   WriteLn(StrToFloat('1.5'));
+
   WriteLn(StrToBool('True'));
 +
  WriteLn(StrToBool('False'));
 +
  WriteLn(StrToBool('true'));
 +
  WriteLn(StrToBool('false'));
 +
  WriteLn(StrToBool('1'));
 +
  WriteLn(StrToBool('0'));
 +
  WriteLn(StrToBool('2'));
 +
  WriteLn(StrToBool('5'));
 
end.
 
end.
 
</source>
 
</source>
  
 
Output:
 
Output:
  1,5
+
  1
 +
0
 +
1
 +
0
 +
1
 +
0
 +
1
 +
1
  
 
==See Also==
 
==See Also==
*[[StrToFloatDef]]
+
*[[StrToBoolDef]]
*[[FloatToStr]]
+
*[[BoolToStr]]
  
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:Conversion Functions]]
 
[[Category:Conversion Functions]]
 
[[Category:Data Functions]]
 
[[Category:Data Functions]]

Latest revision as of 17:02, 5 July 2011

Definition

function StrToBool(Str: AnsiString): Boolean;

Availability

SCAR Divi 3.00 > Current

Description

Converts a given string Str to a boolean value. If Str equals 'false' or '0', the result will be [false], if the Str is 'true' or a string representing any integer value that does not equal 0, the function returns true. In the event that Str is not a valid boolean value, the function will throw an exception.

Example

begin
  WriteLn(StrToBool('True'));
  WriteLn(StrToBool('False'));
  WriteLn(StrToBool('true'));
  WriteLn(StrToBool('false'));
  WriteLn(StrToBool('1'));
  WriteLn(StrToBool('0'));
  WriteLn(StrToBool('2'));
  WriteLn(StrToBool('5'));
end.

Output:

1
0
1
0
1
0
1
1

See Also