Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Integer Built-in Functions

These built-in functions are accessed via the pseudo unit “Integer”

Integer:fromString

Returns an integer representation of the string value expression

 

Info
  1. @Test
  2. void testFromString(){
  3.     string s = "12";
  4.     int value = Integer:fromString(s);
  5.     Assert:isNotNull(value, "Integer:fromString returned null for a valid integer value");
  6.     Assert:isEqual(value, 12, "Integer:fromString returned an incorrect integer value");
  7.  
  8.     s = "abc";
  9.     value = Integer:fromString(s);
  10.     Assert:isNull(value, "Integer:fromString didn't return null for an invalid integer value");
  11. }

 

Decimal Built-in Functions 

These built-in functions are accessed via the pseudo unit “Decimal”

 

Decimal:fromString

Returns an decimal representation of the string value expression

Info

decimal value = Decimal:fromString(s);

 

Uuid Built-in Functions 

These built-in functions are accessed via the pseudo unit “Uuid”

 

Uuid:fromString

Returns an UUID representation of the string value expression
 

 

Info

uuid value = Uuid:fromString(s);

  

 

 

 

 

 

 

 

 

Table of Contents

 

Converting To String

Assigning a non-string value to a string variable implicitly converts the value to string.

Code Block
int i = 12; string s = i; //int to string
decimal d = 12.34; string s = d; //decimal to string

 

 

 

Converting From String

To convert from string to another primitive, use the fromString(s) BIFs available on the corresponding data type namespace.

 

Code Block
languagejava
titleto int
string s = "12"; int i = Integer:fromString(s);
Code Block
languagejava
titleto decimal
decimal d = Decimal:fromString("12.34");
Code Block
languagejava
titleto uuid
uuid id = Uuid:fromString(user._id);
Code Block
languagejava
linenumberstrue
date d = Date:fromString("2017-01-02");

For converting from string to datetime, use Date:fromTimeString(s):

Code Block
datetime dt = Date:fromTimeString("2017-1-20 08:45:12 GMT");

 

 

 

Additional Mentions and References

 

Excerpt
hiddentrue

 Integer / Decimal / Uuid / Date:fromString(s)