fromString

Summary

Converts a string to a short value.

Usage

public static short fromString(string numberAsStr)

Returns

The short equivalent of the string value or zero (0) if the string is not a numeric value.

Parameters

numberAsStr

The string value to convert.

Description

Converts a string to a short value.

import System;

short x = Integer16.fromString("100");
Console.log(x); // 100

If the string being converted is not a valid integer value, zero (0) is returned.

import System;

short x = Integer16.fromString("abc");
Console.log(x); // 0

If the string being converted is numeric but does not fit into the short data range [ -32768, 32767 ] (inclusive), the value will be wrapped: if the value exceeds the short maximum (32,767) by one, it will wrap around to the short minimum (-32,768); if the value exceeds the short maximum by two, it will wrap around to the short minimum plus one (-32,767); and so on.

import System;

short exceedByOne = Integer16.fromString("32768");
Console.log(exceedByOne); // -32768
short exceedByTwo = Integer16.fromString("32769");
Console.log(exceedByTwo); // -32767
short exceedByThree = Integer16.fromString("32770");
Console.log(exceedByThree); // -32766

Examples

Basic Usage
1
2
3
4
import System;
 
short x = Integer16.fromString("100");
Console.log(x); // 100

Share

HTML | BBCode | Direct Link