Method ExtString.ToNumber(+ 6 overloads)
Overload
Converts this string or its part to double number.
public static double ToNumber(this string t, Range? range = null, NumberStyles style = NumberStyles.Float)
Parameters
t (string)
This string. Can be |
range (Range?)
Part of this string or |
style (NumberStyles)
The permitted number format in the string. |
Returns
double
The number, or 0 if failed to convert. |
Exceptions
ArgumentOutOfRangeException
Invalid range. |
ArgumentException
Invalid style. |
Remarks
Calls double.TryParse with System.Globalization.CultureInfoInvariantCulture.
Fails if the string is null
or ""
or isn't a valid floating-point number.
Examples of valid numbers: "12"
, " -12.3 "
, ".12"
, "12."
, "12E3"
, "12.3e-45"
, "1,234.5"
(with styleNumberStyles.Float | NumberStyles.AllowThousands
). String like "2text"
is invalid, unless range is 0..1
.
Overload(next)
Converts this string or its part to double number.
public static bool ToNumber(this string t, out double result, Range? range = null, NumberStyles style = NumberStyles.Float)
Parameters
t (string)
This string. Can be |
result (double)
Receives the result, or 0 if failed. |
range (Range?)
Part of this string or |
style (NumberStyles)
The permitted number format in the string. |
Returns
bool
|
Exceptions
ArgumentOutOfRangeException
Invalid range. |
ArgumentException
Invalid style. |
Remarks
Calls double.TryParse with System.Globalization.CultureInfoInvariantCulture.
Fails if the string is null
or ""
or isn't a valid floating-point number.
Examples of valid numbers: "12"
, " -12.3 "
, ".12"
, "12."
, "12E3"
, "12.3e-45"
, "1,234.5"
(with styleNumberStyles.Float | NumberStyles.AllowThousands
). String like "2text"
is invalid, unless range is 0..1
.
Overload(next)
Converts this string or its part to float number.
public static bool ToNumber(this string t, out float result, Range? range = null, NumberStyles style = NumberStyles.Float)
Parameters
t (string)
This string. Can be |
result (float)
Receives the result, or 0 if failed. |
range (Range?)
Part of this string or |
style (NumberStyles)
The permitted number format in the string. |
Returns
bool
|
Exceptions
ArgumentOutOfRangeException
Invalid range. |
ArgumentException
Invalid style. |
Remarks
Calls float.TryParse with System.Globalization.CultureInfoInvariantCulture.
Overload(next)
Converts this string or its part to int number.
public static bool ToNumber(this string t, out int result, Range? range = null, NumberStyles style = NumberStyles.Integer)
Parameters
t (string)
This string. Can be |
result (int)
Receives the result, or 0 if failed. |
range (Range?)
Part of this string or |
style (NumberStyles)
The permitted number format in the string. |
Returns
bool
|
Exceptions
ArgumentOutOfRangeException
Invalid range. |
ArgumentException
Invalid style. |
Remarks
Calls int.TryParse with System.Globalization.CultureInfoInvariantCulture.
Overload(next)
Converts this string or its part to uint number.
public static bool ToNumber(this string t, out uint result, Range? range = null, NumberStyles style = NumberStyles.Integer)
Parameters
t (string)
This string. Can be |
result (uint)
Receives the result, or 0 if failed. |
range (Range?)
Part of this string or |
style (NumberStyles)
The permitted number format in the string. |
Returns
bool
|
Exceptions
ArgumentOutOfRangeException
Invalid range. |
ArgumentException
Invalid style. |
Remarks
Calls uint.TryParse with System.Globalization.CultureInfoInvariantCulture.
Overload(next)
Converts this string or its part to long number.
public static bool ToNumber(this string t, out long result, Range? range = null, NumberStyles style = NumberStyles.Integer)
Parameters
t (string)
This string. Can be |
result (long)
Receives the result, or 0 if failed. |
range (Range?)
Part of this string or |
style (NumberStyles)
The permitted number format in the string. |
Returns
bool
|
Exceptions
ArgumentOutOfRangeException
Invalid range. |
ArgumentException
Invalid style. |
Remarks
Calls long.TryParse with System.Globalization.CultureInfoInvariantCulture.
Overload(top)
Converts this string or its part to ulong number.
public static bool ToNumber(this string t, out ulong result, Range? range = null, NumberStyles style = NumberStyles.Integer)
Parameters
t (string)
This string. Can be |
result (ulong)
Receives the result, or 0 if failed. |
range (Range?)
Part of this string or |
style (NumberStyles)
The permitted number format in the string. |
Returns
bool
|
Exceptions
ArgumentOutOfRangeException
Invalid range. |
ArgumentException
Invalid style. |
Remarks
Calls ulong.TryParse. Uses System.Globalization.CultureInfo.InvariantCulture if the string range contains only ASCII characters, else uses current culture.