VS:Str2Num: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
(add warning note)
mNo edit summary
Line 37: Line 37:
Author unknown:
Author unknown:


Put this in a file that you include in all of your scripts:
<code lang="pas">
<code lang="pas">
FUNCTION Str2Num(str :STRING) :REAL;
FUNCTION Str2Num(str :STRING) :REAL;

Revision as of 16:30, 17 November 2018

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

Description

Function Str2Num returns the specified string as a numeric value.

FUNCTION Str2Num(
s :STRING) : REAL;
def vs.Str2Num(s):
    return REAL

Parameters

s STRING Source string.

Remarks

(Orso, 18 Nov. 17): Please be careful with overriding standard routines.

Author unknown:

FUNCTION Str2Num(str :STRING) :REAL;
{This over-rides the built-in FUNCTION, and is more
robust because it handles unit marks in the string,
while the built-in FUNCTION does not. Returns zero
if it fails, which of course does not unambiguously
indicate failure, but it's the same thing that Str2Num 
returns on failure (without the warning). If you need
to know whether or not the FUNCTION succeeded, you
shouldn't be using Str2Num, but ValidNumStr instead.}
VAR
num :REAL;
BEGIN
Str2Num := 0;
IF ValidNumStr(str, num) THEN Str2Num := num;
END;

Example

VectorScript

numValue:=Str2Num('235.44');

Python


Version

Availability: from All Versions

See Also

VS Functions:

VS:ValidNumStr

VS Functions: [[VS:ValidNumStr]]