fromString

Summary

Converts a string to an signed byte value.

Usage

public static signed byte fromString(string numberAsStr)

Returns

The signed byte 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 signed byte value.

import System;

signed byte x = Integer8.fromString("100");
Console.log(x); // 100

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

import System;

signed byte x = Integer8.fromString("abc");
Console.log(x); // 0

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

import System;

signed byte exceedByOne = Integer8.fromString("128");
Console.log(exceedByOne); // -128
signed byte exceedByTwo = Integer8.fromString("129");
Console.log(exceedByTwo); // -127
signed byte exceedByThree = Integer8.fromString("130");
Console.log(exceedByThree); // -126

Examples

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

Share

HTML | BBCode | Direct Link