OutputVar := MfInt64.TryParse(result, s)
OubputVar := MfInt64.TryParse(byRef result, s, style[, provider ])
Tries to converts the s representation of a number to its MfInt64 equivalent. A return value indicates whether the conversion succeeded.
result
Contains the value equivalent to the number contained in s, if the conversion succeeded.
The conversion fails if the s parameter is not of the correct format, or represents a number less than MinValue or greater than MaxValue.
s
An object to convert.
Can be var or instance of MfChar, MfString
Returns true if parse is a success; Otherwise false
Throws MfInvalidOperationException if not called as static method.
The conversion fails and the method returns false if the s parameter is not in the correct format, if it is null, or if it represents a number less than MinValue or greater than MaxValue.
The MfInt64.TryParse(result, s) method is similar to the MfInt64.Parse(s) method, except that MfInt64.TryParse(result, s) does not throw an exception if the conversion fails.
The s parameter contains a number of the form:
[ws][sign]digits[ws]
Elements in square brackets ([ and ]) are optional. The following table describes each element.
Element |
Description |
ws |
Optional white space. |
sign |
An optional positive or negative sign. |
digits |
A sequence of digits ranging from 0 to 9 |
The s parameter is interpreted using the MfNumberStyles.Integer style. In addition to the byte value's decimal digits, only leading and trailing spaces together with a leading sign are allowed. (If the sign is present, it must be a positive sign or the method throws an MfOverFlowExcpetion.)
sb := new MfText.StringBuilder()
TryToParse(Null, sb)
TryToParse("16051", sb)
TryToParse("9432.0", sb)
TryToParse("16,667", sb)
TryToParse(" -322 ", sb)
TryToParse("+4302", sb)
TryToParse("(100);", sb)
TryToParse("01FA", sb)
MsgBox % sb.ToString()
TryToParse(value, sb) {
number := MfInt64
result := MfInt64.TryParse(number, value)
if (result)
{
sb.AppendFormat("Converted '{0}' to {1}.", value, number)
sb.AppendLine()
}
else
{
if (MfNull.IsNull(Value))
{
value := ""
}
sb.AppendFormat("Attempted conversion of '{0}' failed.", value)
sb.AppendLine()
}
}
/*
Attempted conversion of '' failed.
Converted '16051' to 16051.
Attempted conversion of '9432.0' failed.
Attempted conversion of '16,667' failed.
Converted ' -322 ' to -322.
Converted '+4302' to 4302.
Attempted conversion of '(100);' failed.
Attempted conversion of '01FA' failed.
*/
Tries to converts the s representation of a number to its MfInt64 equivalent. A return value indicates whether the conversion succeeded.
result
Contains the value equivalent to the number contained in s, if the conversion succeeded.
The conversion fails if the s parameter is not of the correct format, or represents a number less than MinValue or greater than MaxValue.
s
An string var of object convert.
Can be var or instance of MfChar, MfString
style
MfNumberStyles Instance or Integer var representing instance.
A bitwise combination of MfNumberStyles values that indicates the style elements that can be present in s. A typical value to specify is MfNumberStyles.Integer.
provider
An Optional object that supplies culture-specific parsing information about s. If provider is null, then MfNumberFormatInfo is used.
Returns true if parse is a success; Otherwise false
Throws MfInvalidOperationException if not called as static method.
Throws MfArgumentException style is not a MfNumberStyles value.
-or-
style is not a combination of MfNumberStyles.AllowHexSpecifier and MfNumberStyles.HexNumber values.
The TryParse method is like the Parse method, except the TryParse method does not throw an exception if the conversion fails. It eliminates the need to use exception handling to test for a MfFormatException in the event that s is invalid and cannot be parsed successfully.
The style parameter defines the style elements (such as white space or a positive or negative sign) that are allowed in the s parameter for the parse operation to succeed. It must be a combination of bit flags from the NumberStyles enumeration.
The style parameter defines the style elements (such as white space or the positive sign) that are allowed in the s parameter for the parse operation to succeed. It must be a combination of bit flags from the MfNumberStyles enumeration. Depending on the value of style, the s parameter may include the following elements:
[ws][$][sign]digits[.fractional_digits][e[sign]digits][ws]
Elements in square brackets ([ and ]) are optional. The following table describes each element.
Element |
Description |
ws |
Optional white space. White space can appear at the beginning of s if style includes the MfNumberStyles.AllowLeadingWhite flag, or at the end of s if style includes the MfNumberStyles.AllowTrailingWhite flag. |
$ |
A currency symbol. Its position in the string is defined by the MfNumberFormatInfo.CurrencyPositivePattern property. The current culture's currency symbol can appear in s if style includes the MfNumberStyles.AllowCurrencySymbol flag. |
sign |
An optional positive or negative sign. |
digits |
A sequence of digits ranging from 0 to 9 |
. |
A decimal point symbol. The default decimal point symbol can appear in s if style includes the MfNumberStyles.AllowDecimalPoint flag. |
fractional_digits |
One or more occurrences of the digit 0. Fractional digits can appear in s only if style includes the MfNumberStyles.AllowDecimalPoint flag. |
e |
The e or E character, which indicates that the value is represented in exponential notation. The s parameter can represent a number in exponential notation if style includes the MfNumberStyles.AllowExponent flag. |
hexdigits |
A sequence of hexadecimal digits from 0 through f, or 0 through F. |
A string with decimal digits only (which corresponds to the MfNumberStyles.None style) always parses successfully. Most of the remaining MfNumberStyles enumerations control elements that may be but are not required to be present in this input string. The following table indicates how individual MfNumberStyles enumerations affect the elements that may be present in s.
Non-composite NumberStyles values |
Elements permitted in s in addition to digits |
Decimal digits only. |
|
The . and fractional_digits elements. However, fractional_digits must consist of only one or more 0 digits or an MfOverflowException is thrown. |
|
The s parameter can also use exponential notation. |
|
The ws element at the beginning of s. |
|
The ws element at the end of s. |
|
A positive sign can appear before digits. |
|
A positive sign can appear after digits. |
|
Although this flag is supported, the use of parentheses in s results in an MfOverflowException. |
|
Although the group separator symbol can appear in s, it can be preceded by only one or more 0 digits. |
|
The $ element. |
If the MfNumberStyles.AllowHexSpecifier flag is used, s must be a hexadecimal value without a prefix. For example, "C9AF3" parses successfully, but "0xC9AF3" does not. The only other flags that can be combined with it are MfNumberStyles.AllowLeadingWhite and MfNumberStyles.AllowTrailingWhite. (The MfNumberStyles enumeration includes a composite number style, MfNumberStyles.HexNumber, that includes both white space flags.)
The provider parameter is an MfFormatProvider implementation, such as a MFNumberFormatInfo object, whose GetFormat method returns a MFNumberFormatInfo object. The MFNumberFormatInfo object provides culture-specific information about the format of s.
sb := new MfText.StringBuilder()
numericString := "106779"
styles := MfNumberStyles.Instance.Integer
CallTryParse(numericString, styles, sb)
numericString := "-30677"
styles := MfNumberStyles.Instance.None
CallTryParse(numericString, styles, sb)
numericString := "301677-"
styles := MfNumberStyles.Instance.AllowLeadingSign.Value
CallTryParse(numericString, styles, sb)
styles := styles | MfNumberStyles.Instance.AllowTrailingSign.Value
CallTryParse(numericString, styles, sb)
numericString := "$10634"
styles := MfNumberStyles.Instance.Integer
CallTryParse(numericString, styles, sb)
styles := MfNumberStyles.Instance.Integer.Value | MfNumberStyles.Instance.AllowCurrencySymbol.Value
CallTryParse(numericString, styles, sb)
numericString := "10345.00"
styles := MfNumberStyles.Instance.Integer.Value | MfNumberStyles.Instance.AllowDecimalPoint.Value
CallTryParse(numericString, styles, sb)
numericString := "10345.72"
styles := MfNumberStyles.Instance.Integer.Value | MfNumberStyles.Instance.AllowDecimalPoint.Value
CallTryParse(numericString, styles, sb)
numericString := "22,593"
styles := MfNumberStyles.Instance.Integer.Value | MfNumberStyles.Instance.AllowThousands.Value
CallTryParse(numericString, styles, sb)
numericString := "12E-01"
styles := MfNumberStyles.Instance.Integer.Value | MfNumberStyles.Instance.AllowExponent.Value
CallTryParse(numericString, styles, sb)
numericString := "12E03"
CallTryParse(numericString, styles, sb)
numericString := "80c1"
CallTryParse(numericString, MfNumberStyles.Instance.HexNumber, sb)
numericString := "0x80C1"
CallTryParse(numericString, MfNumberStyles.Instance.HexNumber, sb)
MsgBox % sb.ToString()
CallTryParse(stringToConvert, styles, sb)
{
number := MfInt64
result := MfInt64.TryParse(number, stringToConvert, styles, MfNumberFormatInfo.InvariantInfo)
if (result)
{
sb.AppendFormat("Converted '{0}' to {1}.", stringToConvert, number)
sb.AppendLine()
}
else
{
sb.AppendFormat("Attempted conversion of '{0}' failed.", MfString.GetValue(stringToConvert))
sb.AppendLine()
}
}
/*
Converted '106779' to 106779.
Attempted conversion of '-30677' failed.
Attempted conversion of '301677-' failed.
Converted '301677-' to -301677.
Attempted conversion of '$10634' failed.
Converted '$10634' to 10634.
Converted '10345.00' to 10345.
Attempted conversion of '10345.72' failed.
Converted '22,593' to 22593.
Attempted conversion of '12E-01' failed.
Converted '12E03' to 12000.
Converted '80c1' to 32961.
Attempted conversion of '0x80C1' failed.
*/