Int64Static: TryParse

TryParse

Converts the string representation of a number to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.



 Public Function TryParse(
	  ByRef s As String,
	  ByRef Result As Int64 ) As Boolean

Parameters

s
[ByRef] String. A string containing a number to convert.
Result
[ByRef] Int64. When this method returns, contains the 64-bit signed integer value equivalent of the number contained in s, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is empty, is not in a format compliant withstyle, or represents a number less than MinValue or greater than MaxValue. This parameter is passed uninitialized; any value originally supplied in Result will be overwritten.

Return Values

Boolean -  True if s was converted successfully; otherwise, False.

Remarks

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 FormatException in the event that s is invalid and cannot be successfully parsed.

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
wsOptional white space.
signAn optional sign.
digitsA sequence of digits ranging from 0 to 9.

The s parameter is interpreted using the NumberStyles.Integer style. In addition to decimal digits, only leading and trailing spaces together with a leading sign are allowed. To explicitly define the style elements that can be present in s, use Int64.ParseEx(String, NumberStyles) or the Int64.Parse(String, NumberStyles, IFormatProvider) method.

A string expression beginning with "0x" or "&h" will be parsed as a hex value.

See Also

Project CorLib Overview

Class Int64Static Overview

Parse

ParseEx

TryParseEx