Parse Method (String)
Collapse the table of content
Expand the table of content

SByte.Parse Method (String)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Converts the string representation of a number to its 8-bit signed integer equivalent.

This API is not CLS-compliant. The CLS-compliant alternative is Parse(String).

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
<CLSCompliantAttribute(False)> _
Public Shared Function Parse ( _
	s As String _
) As SByte

Parameters

s
Type: System.String
A string that represents a number to convert. The string is interpreted using the NumberStyles.Integer style.

Return Value

Type: System.SByte
An 8-bit signed integer that is equivalent to the number contained in the s parameter.

ExceptionCondition
ArgumentException

s is Nothing.

FormatException

s does not consist of an optional sign followed by a sequence of digits (zero through nine).

OverflowException

s represents a number less than MinValue or greater than MaxValue.

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 sign.

digits

A sequence of digits ranging from 0 to 9.

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

The s parameter is parsed by using the formatting information in a NumberFormatInfo that is initialized for the current system culture. For more information, see NumberFormatInfo.CurrentInfo. To parse a string by using the formatting information of some other culture, use the Parse(String, NumberStyles, IFormatProvider) method.

The following example demonstrates how to convert a string value into a signed byte value using the Parse method. The resulting signed byte value is then displayed to the console.


' Define an array of numeric strings.
Dim values() As String = { "-16", "  -3", "+ 12", " +12 ", "  12  ", _
                           "+120", "(103)", "192", "-160" }

' Parse each string and display the result.
For Each value As String In values
   Try
      outputBlock.Text += String.Format("Converted '{0}' to the SByte value {1}.", _
                        value, SByte.Parse(value)) + Environment.NewLine
   Catch e As FormatException
      outputBlock.Text += String.Format("'{0}' cannot be parsed successfully by SByte type.", _
                        value) + Environment.NewLine
   Catch e As OverflowException
      outputBlock.Text += String.Format("'{0}' is out of range of the SByte type.", _
                        value) + Environment.NewLine
   End Try                                                                        
Next        
' The example displays the following output:
'       Converted '-16' to the SByte value -16.
'       Converted '  -3' to the SByte value -3.
'       '+ 12' cannot be parsed successfully by SByte type.
'       Converted ' +12 ' to the SByte value 12.
'       Converted '  12  ' to the SByte value 12.
'       Converted '+120' to the SByte value 120.
'       '(103)' cannot be parsed successfully by SByte type.
'       '192' is out of range of the SByte type.
'       '-160' is out of range of the SByte type.


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft