fromString

Summary

Converts a string to an unsigned int value.

Usage

public static unsigned int fromString(string numberAsStr)

Returns

The unsigned int 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 an unsigned int value.

import System;

unsigned int x = UInteger32.fromString("100");
Console.log(x); // 100

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

import System;

unsigned int x = UInteger32.fromString("abc");
Console.log(x); // 0

If the string being converted is numeric but does not fit into the unsigned int data range [ 0, 4294967295 ] (inclusive), the value will be wrapped: if the value exceeds the unsigned int maximum (4,294,967,295) by one, it will wrap around to the unsigned int minimum (0); if the value exceeds the unsigned int maximum by two, it will wrap around to the unsigned int minimum plus one (1); and so on.

import System;

unsigned int exceedByOne = UInteger32.fromString("4294967296");
Console.log(exceedByOne); // 0
unsigned int exceedByTwo = UInteger32.fromString("4294967297");
Console.log(exceedByTwo); // 1
unsigned int exceedByThree = UInteger32.fromString("4294967298");
Console.log(exceedByThree); // 2

Examples

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

Share

HTML | BBCode | Direct Link