Int16.Parse Int16.Parse Int16.Parse Int16.Parse Method

定義

数値の文字列形式を、それと等価な 16 ビット符号付き整数に変換します。Converts the string representation of a number to its 16-bit signed integer equivalent.

オーバーロード

Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider)

指定したスタイルおよびカルチャに固有の書式による数値の文字列形式を、それと等価の 16 ビット符号付き整数に変換します。Converts the string representation of a number in a specified style and culture-specific format to its 16-bit signed integer equivalent.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles)

指定したスタイルの数値の文字列形式を、それと等価の 16 ビット符号付き整数に変換します。Converts the string representation of a number in a specified style to its 16-bit signed integer equivalent.

Parse(String) Parse(String) Parse(String) Parse(String)

数値の文字列形式を、それと等価な 16 ビット符号付き整数に変換します。Converts the string representation of a number to its 16-bit signed integer equivalent.

Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider)

指定したカルチャに固有の書式による数値の文字列形式を、それと等価な 16 ビット符号付き整数に変換します。Converts the string representation of a number in a specified culture-specific format to its 16-bit signed integer equivalent.

Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider)

指定したスタイルおよびカルチャに固有の書式による数値の文字列形式を、それと等価の 16 ビット符号付き整数に変換します。Converts the string representation of a number in a specified style and culture-specific format to its 16-bit signed integer equivalent.

public:
 static short Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider);
public static short Parse (string s, System.Globalization.NumberStyles style, IFormatProvider provider);
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> int16
Public Shared Function Parse (s As String, style As NumberStyles, provider As IFormatProvider) As Short

パラメーター

s
String String String String

変換する数値を含む文字列。A string containing a number to convert.

style
NumberStyles NumberStyles NumberStyles NumberStyles

s で存在する可能性を持つスタイル要素を示す、列挙値のビットごとの組み合わせ。A bitwise combination of enumeration values that indicates the style elements that can be present in s. 通常指定する値は、Integer です。A typical value to specify is Integer.

provider
IFormatProvider IFormatProvider IFormatProvider IFormatProvider

s に関するカルチャに固有の書式設定情報を提供する IFormatProviderAn IFormatProvider that supplies culture-specific formatting information about s.

戻り値

s で指定した数値と等しい 16 ビット符号付き整数。A 16-bit signed integer equivalent to the number specified in s.

例外

styleNumberStyles 値ではありません。style is not a NumberStyles value.

または-or- styleAllowHexSpecifier 値と HexNumber 値の組み合わせではありません。style is not a combination of AllowHexSpecifier and HexNumber values.

s の形式が style に準拠していません。s is not in a format compliant with style.

s は、MinValue 未満の数値か、MaxValue より大きい数値を表します。s represents a number less than MinValue or greater than MaxValue.

または-or- s に 0 以外の小数の桁数が含まれています。s includes non-zero fractional digits.

次の例は、さまざまなstyleproviderパラメーターの文字列形式を解析するInt16値。The following example uses a variety of style and provider parameters to parse the string representations of Int16 values.

String^ value;
Int16 number;
NumberStyles style;

// Parse string using "." as the thousands separator 
// and " " as the decimal separator.
value = "19 694,00";
style = NumberStyles::AllowDecimalPoint | NumberStyles::AllowThousands;
CultureInfo^ provider = gcnew CultureInfo("fr-FR");

number = Int16::Parse(value, style, provider);
Console::WriteLine("'{0}' converted to {1}.", value, number);
// Displays:
//    '19 694,00' converted to 19694.

try
{
   number = Int16::Parse(value, style, CultureInfo::InvariantCulture);
   Console::WriteLine("'{0}' converted to {1}.", value, number);
}
catch (FormatException ^e)
{
   Console::WriteLine("Unable to parse '{0}'.", value);
}
// Displays:
//    Unable to parse '19 694,00'.

// Parse string using "$" as the currency symbol for en_GB and
// en-US cultures.
value = "$6,032.00";
style = NumberStyles::Number | NumberStyles::AllowCurrencySymbol;
provider = gcnew CultureInfo("en-GB");

try
{
   number = Int16::Parse(value, style, CultureInfo::InvariantCulture);
   Console::WriteLine("'{0}' converted to {1}.", value, number);
}
catch (FormatException ^e)
{
   Console::WriteLine("Unable to parse '{0}'.", value);
}
// Displays:
//    Unable to parse '$6,032.00'.
                        
provider = gcnew CultureInfo("en-US");
number = Int16::Parse(value, style, provider);
Console::WriteLine("'{0}' converted to {1}.", value, number);
// Displays:
//    '$6,032.00' converted to 6032.      
string value;
short number;
NumberStyles style;
CultureInfo provider;

// Parse string using "." as the thousands separator 
// and " " as the decimal separator.
value = "19 694,00";
style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
provider = new CultureInfo("fr-FR");

number = Int16.Parse(value, style, provider);
Console.WriteLine("'{0}' converted to {1}.", value, number);
// Displays:
//    '19 694,00' converted to 19694.

try
{
   number = Int16.Parse(value, style, CultureInfo.InvariantCulture);
   Console.WriteLine("'{0}' converted to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", value);
}
// Displays:
//    Unable to parse '19 694,00'.

// Parse string using "$" as the currency symbol for en_GB and
// en-US cultures.
value = "$6,032.00";
style = NumberStyles.Number | NumberStyles.AllowCurrencySymbol;
provider = new CultureInfo("en-GB");

try
{
   number = Int16.Parse(value, style, CultureInfo.InvariantCulture);
   Console.WriteLine("'{0}' converted to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", value);
}
// Displays:
//    Unable to parse '$6,032.00'.
                        
provider = new CultureInfo("en-US");
number = Int16.Parse(value, style, provider);
Console.WriteLine("'{0}' converted to {1}.", value, number);
// Displays:
//    '$6,032.00' converted to 6032.      
Dim value As String
Dim number As Short
Dim style As NumberStyles
Dim provider As CultureInfo

' Parse string using "." as the thousands separator 
' and " " as the decimal separator.
value = "19 694,00"
style = NumberStyles.AllowDecimalPoint Or NumberStyles.AllowThousands
provider = New CultureInfo("fr-FR")

number = Int16.Parse(value, style, provider)
Console.WriteLine("'{0}' converted to {1}.", value, number)
' Displays:
'    '19 694,00' converted to 19694.

Try
   number = Int16.Parse(value, style, CultureInfo.InvariantCulture)
   Console.WriteLine("'{0}' converted to {1}.", value, number)
Catch e As FormatException
   Console.WriteLine("Unable to parse '{0}'.", value)
End Try
' Displays:
'    Unable to parse '19 694,00'.

' Parse string using "$" as the currency symbol for en_GB and
' en-US cultures.
value = "$6,032.00"
style = NumberStyles.Number Or NumberStyles.AllowCurrencySymbol
provider = New CultureInfo("en-GB")

Try
   number = Int16.Parse(value, style, CultureInfo.InvariantCulture)
   Console.WriteLine("'{0}' converted to {1}.", value, number)
Catch e As FormatException
   Console.WriteLine("Unable to parse '{0}'.", value)
End Try
' Displays:
'    Unable to parse '$6,032.00'.
                        
provider = New CultureInfo("en-US")
number = Int16.Parse(value, style, provider)
Console.WriteLine("'{0}' converted to {1}.", value, number)
' Displays:
'    '$6,032.00' converted to 6032.      

注釈

style (空白や正符号) で使用できるスタイル要素を定義するパラメーター、s解析操作が成功するためのパラメーター。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. ビット フラグの組み合わせがあります、NumberStyles列挙体。It must be a combination of bit flags from the NumberStyles enumeration. 値に応じてstylesパラメーターは、次の要素を含めることができます。Depending on the value of style, the s parameter may include the following elements:

[ws][$][sign][digits,]digits[.fractional_digits][e[sign]digits][ws][ws][$][sign][digits,]digits[.fractional_digits][e[sign]digits][ws]

または、styleが含まれていますAllowHexSpecifier:Or, if style includes AllowHexSpecifier:

[ws] hexdigits [ws][ws]hexdigits[ws]

角かっこ ([ および ]) 内の要素は省略可能です。Elements in square brackets ([ and ]) are optional. 次の表は、それぞれの要素の説明です。The following table describes each element.

要素Element 説明Description
wsws 空白文字の省略可能です。Optional white space. 先頭に空白文字を表示できるs場合styleが含まれています、NumberStyles.AllowLeadingWhiteフラグ、または末尾のs場合styleが含まれています、NumberStyles.AllowTrailingWhiteフラグ。White space can appear at the beginning of s if style includes the NumberStyles.AllowLeadingWhite flag, or at the end of s if style includes the NumberStyles.AllowTrailingWhite flag.
$ カルチャ固有の通貨記号。A culture-specific currency symbol. によって、文字列内の位置が定義されている、NumberFormatInfo.CurrencyPositivePatternNumberFormatInfo.CurrencyNegativePattern現在のカルチャのプロパティ。Its position in the string is defined by the NumberFormatInfo.CurrencyPositivePattern and NumberFormatInfo.CurrencyNegativePattern property of the current culture. 現在のカルチャの通貨記号に表示されるs場合styleが含まれています、NumberStyles.AllowCurrencySymbolフラグ。The current culture's currency symbol can appear in s if style includes the NumberStyles.AllowCurrencySymbol flag.
signsign オプションの符号。An optional sign. 先頭の符号が表示できるs場合styleが含まれています、NumberStyles.AllowLeadingSignの最後に、フラグ、およびそれが表示されるs場合styleが含まれています、NumberStyles.AllowTrailingSignフラグ。The sign can appear at the beginning of s if style includes the NumberStyles.AllowLeadingSign flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingSign flag. かっこを使用できるs負の値を指定する場合styleが含まれています、NumberStyles.AllowParenthesesフラグ。Parentheses can be used in s to indicate a negative value if style includes the NumberStyles.AllowParentheses flag.
数字digits 0 ~ 9 桁の数字のシーケンス。A sequence of digits from 0 through 9.
, カルチャ固有の桁区切り記号。A culture-specific thousands separator symbol. 数千の現在のカルチャの区切り記号に表示されるs場合styleが含まれています、NumberStyles.AllowThousandsフラグ。The current culture's thousands separator symbol can appear in s if style includes the NumberStyles.AllowThousands flag.
.. カルチャに固有の小数点記号。A culture-specific decimal point symbol. 現在のカルチャの小数点記号に表示されるs場合styleが含まれています、NumberStyles.AllowDecimalPointフラグ。The current culture's decimal point symbol can appear in s if style includes the NumberStyles.AllowDecimalPoint flag.
fractional_digitsfractional_digits 0 の数字のシーケンス。A sequence of the 0 digit. 小数部の桁数を表示できるs場合styleが含まれています、NumberStyles.AllowDecimalPointフラグ。Fractional digits can appear in s if style includes the NumberStyles.AllowDecimalPoint flag. 0 以外の任意の数字が表示される場合fractional_digitsがスローされます、OverflowExceptionします。If any digit other than 0 appears in fractional_digits, the method throws an OverflowException.
ee "E"または"E"文字は、ことを示しますs指数表記で表すことができます。The 'e' or 'E' character, which indicates that s can be represented in exponential notation. sパラメーターは指数表記の数値を表すことができる場合styleが含まれています、NumberStyles.AllowExponentフラグ。The s parameter can represent a number in exponential notation if style includes the NumberStyles.AllowExponent flag. ただし、sパラメーターの範囲内の数を表す必要があります、Int16データ型で、0 以外の小数部を含めることはできません。However, the s parameter must represent a number in the range of the Int16 data type and cannot have a non-zero fractional component.
hexdigitshexdigits 0 ~ f、または f の 0 から 16 進数のシーケンスA sequence of hexadecimal digits from 0 through f, or 0 through F.

注意

終端の NUL (u+0000) 文字sの値に関係なく、解析操作では無視されますが、style引数。Any terminating NUL (U+0000) characters in s are ignored by the parsing operation, regardless of the value of the style argument.

String とのみ (に対応する、NumberStyles.Noneスタイル) 常に正常に解析します。A string with digits only (which corresponds to the NumberStyles.None style) always parses successfully. 残りのほとんどNumberStylesメンバーがありますが、この入力文字列内に存在する必要はありません要素を制御します。Most of the remaining NumberStyles members control elements that may be but are not required to be present in this input string. 次の表に示す個別NumberStylesメンバー内に存在する要素に影響を与えるsします。The following table indicates how individual NumberStyles members affect the elements that may be present in s.

非複合 NumberStyles 値Non-composite NumberStyles values 数字だけでなく s で許可されている要素Elements permitted in s in addition to digits
NumberStyles.None 10 進数字のみです。Decimal digits only.
NumberStyles.AllowDecimalPoint .The . fractional_digits要素。and fractional_digits elements. ただし、 fractional_digitsのみ 1 つまたは複数の 0 の数字で構成する必要がありますまたはOverflowExceptionがスローされます。However, fractional_digits must consist of only one or more 0 digits or an OverflowException is thrown.
NumberStyles.AllowExponent sパラメーターは、指数表記も使用できます。The s parameter can also use exponential notation.
NumberStyles.AllowLeadingWhite Wsの先頭にある要素sします。The ws element at the beginning of s.
NumberStyles.AllowTrailingWhite Wsの末尾にある要素sします。The ws element at the end of s.
NumberStyles.AllowLeadingSign 符号は、前に配置できますします。A sign can appear before digits.
NumberStyles.AllowTrailingSign 符号が後に表示できるします。A sign can appear after digits.
NumberStyles.AllowParentheses サインオン形式の数値を囲むかっこ内の要素。The sign element in the form of parentheses enclosing the numeric value.
NumberStyles.AllowThousands 要素。The , element.
NumberStyles.AllowCurrencySymbol $ 要素。The $ element.

場合、NumberStyles.AllowHexSpecifierフラグを使用すると、sプレフィックスなしの 16 進数の値の文字列形式を指定する必要があります。If the NumberStyles.AllowHexSpecifier flag is used, s must be the string representation of a hexadecimal value without a prefix. たとえば、"9AF3"が正常に解析しますが、"0x9AF3"は使用できません.For example, "9AF3" parses successfully, but "0x9AF3" does not.. 他のフラグのみに存在することができるstyleNumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteします。The only other flags that can be present in style are NumberStyles.AllowLeadingWhite and NumberStyles.AllowTrailingWhite. (、NumberStyles列挙体には複合数値スタイル、 NumberStyles.HexNumber、空白文字の両方のフラグが含まれます)。(The NumberStyles enumeration has a composite number style, NumberStyles.HexNumber, that includes both white space flags.)

providerパラメーターが、IFormatProvider実装がGetFormatメソッドは、取得、NumberFormatInfoオブジェクト。The provider parameter is an IFormatProvider implementation whose GetFormat method obtains a NumberFormatInfo object. NumberFormatInfoオブジェクトの書式設定に関するカルチャ固有の情報を提供sします。The NumberFormatInfo object provides culture-specific information about the format of s. 場合providernullNumberFormatInfoオブジェクトの現在のカルチャが使用されます。If provider is null, the NumberFormatInfo object for the current culture is used.

こちらもご覧ください

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

public static short Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider provider = null);
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> int16
Public Shared Function Parse (s As ReadOnlySpan(Of Char), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = null) As Short

パラメーター

戻り値

Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles)

指定したスタイルの数値の文字列形式を、それと等価の 16 ビット符号付き整数に変換します。Converts the string representation of a number in a specified style to its 16-bit signed integer equivalent.

public:
 static short Parse(System::String ^ s, System::Globalization::NumberStyles style);
public static short Parse (string s, System.Globalization.NumberStyles style);
static member Parse : string * System.Globalization.NumberStyles -> int16
Public Shared Function Parse (s As String, style As NumberStyles) As Short

パラメーター

s
String String String String

変換する数値を含む文字列。A string containing a number to convert.

style
NumberStyles NumberStyles NumberStyles NumberStyles

s で使用可能なスタイル要素を示す、列挙値のビットごとの組み合わせ。A bitwise combination of the enumeration values that indicates the style elements that can be present in s. 通常指定する値は、Integer です。A typical value to specify is Integer.

戻り値

s で指定した数値と等しい 16 ビット符号付き整数。A 16-bit signed integer equivalent to the number specified in s.

例外

styleNumberStyles 値ではありません。style is not a NumberStyles value.

または-or- styleAllowHexSpecifier 値と HexNumber 値の組み合わせではありません。style is not a combination of AllowHexSpecifier and HexNumber values.

s の形式が style に準拠していません。s is not in a format compliant with style.

s は、MinValue 未満の数値か、MaxValue より大きい数値を表します。s represents a number less than MinValue or greater than MaxValue.

または-or- s に 0 以外の小数の桁数が含まれています。s includes non-zero fractional digits.

次の例では、Int16.Parse(String, NumberStyles)メソッドの文字列形式を解析するInt16EN-US カルチャを使用して値します。The following example uses the Int16.Parse(String, NumberStyles) method to parse the string representations of Int16 values using the en-US culture.

using namespace System;
using namespace System::Globalization;

ref class ParseSample
{
public:
   static void Main()
   {
      String^ value;
      NumberStyles style;

      // Parse a number with a thousands separator (throws an exception).
      value = "14,644";
      style = NumberStyles::None;
      ParseSample::ParseToInt16(value, style);
      
      style = NumberStyles::AllowThousands;
      ParseToInt16(value, style);
      
      // Parse a number with a thousands separator and decimal point.
      value = "14,644.00";
      style = NumberStyles::AllowThousands | NumberStyles::Integer |
              NumberStyles::AllowDecimalPoint;
      ParseToInt16(value, style);
      
      // Parse a number with a fractional component (throws an exception).
      value = "14,644.001";
      ParseToInt16(value, style);
      
      // Parse a number in exponential notation.
      value = "145E02";
      style = style | NumberStyles::AllowExponent;
      ParseToInt16(value, style);
      
      // Parse a number in exponential notation with a positive sign.
      value = "145E+02";
      ParseToInt16(value, style);
      
      // Parse a number in exponential notation with a negative sign
      // (throws an exception).
      value = "145E-02";
      ParseToInt16(value, style);
   }

private:
   static void ParseToInt16(String^ value, NumberStyles style)
   {
      try
      {
         Int16 number = Int16::Parse(value, style);
         Console::WriteLine("Converted '{0}' to {1}.", value, number);
      }
      catch (FormatException ^e)
      {
         Console::WriteLine("Unable to parse '{0}' with style {1}.", value, 
                            style);
      }
      catch (OverflowException ^e)
      {
         Console::WriteLine("'{0}' is out of range of the Int16 type.", value);
      }
   }
};

int main()
{
    ParseSample::Main();
    Console::ReadLine();
    return 0;
}
// The example displays the following output:
//       Unable to parse '14,644' with style None.
//       Converted '14,644' to 14644.
//       Converted '14,644.00' to 14644.
//       '14,644.001' is out of range of the Int16 type.
//       Converted '145E02' to 14500.
//       Converted '145E+02' to 14500.
//       '145E-02' is out of range of the Int16 type.
using System;
using System.Globalization;

public class ParseSample
{
   public static void Main()
   {
      string value; 
      NumberStyles style;
      
      // Parse a number with a thousands separator (throws an exception).
      value = "14,644";
      style = NumberStyles.None;
      ParseToInt16(value, style);
      
      style = NumberStyles.AllowThousands;
      ParseToInt16(value, style);
      
      // Parse a number with a thousands separator and decimal point.
      value = "14,644.00";
      style = NumberStyles.AllowThousands | NumberStyles.Integer |
              NumberStyles.AllowDecimalPoint;
      ParseToInt16(value, style);
      
      // Parse a number with a fractional component (throws an exception).
      value = "14,644.001";
      ParseToInt16(value, style);
      
      // Parse a number in exponential notation.
      value = "145E02";
      style = style | NumberStyles.AllowExponent;
      ParseToInt16(value, style);
      
      // Parse a number in exponential notation with a positive sign.
      value = "145E+02";
      ParseToInt16(value, style);
      
      // Parse a number in exponential notation with a negative sign
      // (throws an exception).
      value = "145E-02";
      ParseToInt16(value, style);
   }

   private static void ParseToInt16(string value, NumberStyles style)
   {
      try
      {
         short number = Int16.Parse(value, style);
         Console.WriteLine("Converted '{0}' to {1}.", value, number);
      }
      catch (FormatException)
      {
         Console.WriteLine("Unable to parse '{0}' with style {1}.", value, 
                           style.ToString());
      }
      catch (OverflowException)
      {
         Console.WriteLine("'{0}' is out of range of the Int16 type.", value);
      }
   }   
}
// The example displays the following output to the console:
//       Unable to parse '14,644' with style None.
//       Converted '14,644' to 14644.
//       Converted '14,644.00' to 14644.
//       '14,644.001' is out of range of the Int16 type.
//       Converted '145E02' to 14500.
//       Converted '145E+02' to 14500.
//       '145E-02' is out of range of the Int16 type.
Imports System.Globalization

Module ParseSample
   Public Sub Main()
      Dim value As String 
      Dim style As NumberStyles
      
      ' Parse a number with a thousands separator (throws an exception).
      value = "14,644"
      style = NumberStyles.None
      ParseToInt16(value, style)
      
      style = NumberStyles.AllowThousands
      ParseToInt16(value, style)
      
      ' Parse a number with a thousands separator and decimal point.
      value = "14,644.00"
      style = NumberStyles.AllowThousands Or NumberStyles.Integer Or _
              NumberStyles.AllowDecimalPoint
      ParseToInt16(value, style)
      
      ' Parse a number with a fractional component (throws an exception).
      value = "14,644.001"
      ParseToInt16(value, style)
      
      ' Parse a number in exponential notation.
      value = "145E02"
      style = style Or NumberStyles.AllowExponent
      ParseToInt16(value, style)
      
      ' Parse a number in exponential notation with a positive sign.
      value = "145E+02"
      ParseToInt16(value, style)
      
      ' Parse a number in exponential notation with a negative sign
      ' (throws an exception).
      value = "145E-02"
      ParseToInt16(value, style)
   End Sub
   
   Private Sub ParseToInt16(value As String, style As NumberStyles)
      Try
         Dim number As Short = Int16.Parse(value, style)
         Console.WriteLine("Converted '{0}' to {1}.", value, number)
      Catch e As FormatException
         Console.WriteLine("Unable to parse '{0}' with style {1}.", value, _
                           style.ToString())
      Catch e As OverflowException
         Console.WriteLine("'{0}' is out of range of the Int16 type.", value)
      End Try
   End Sub   
End Module
' The example displays the following output to the console:
'       Unable to parse '14,644' with style None.
'       Converted '14,644' to 14644.
'       Converted '14,644.00' to 14644.
'       '14,644.001' is out of range of the Int16 type.
'       Converted '145E02' to 14500.
'       Converted '145E+02' to 14500.
'       '145E-02' is out of range of the Int16 type.

注釈

style (空白文字の記号など) で使用できるスタイル要素を定義するパラメーター、s解析操作が成功するためのパラメーター。The style parameter defines the style elements (such as white space or a sign symbol) that are allowed in the s parameter for the parse operation to succeed. ビット フラグの組み合わせがあります、NumberStyles列挙体。It must be a combination of bit flags from the NumberStyles enumeration. 値に応じてstylesパラメーターは、次の要素を含めることができます。Depending on the value of style, the s parameter may include the following elements:

[ws][$][sign][digits,]digits[.fractional_digits][e[sign]digits][ws][ws][$][sign][digits,]digits[.fractional_digits][e[sign]digits][ws]

または、styleが含まれていますAllowHexSpecifier:Or, if style includes AllowHexSpecifier:

[ws] hexdigits [ws][ws]hexdigits[ws]

角かっこ ([と]) は任意の項目です。Items in square brackets ([ and ]) are optional. 次の表は、それぞれの要素の説明です。The following table describes each element.

要素Element 説明Description
wsws 空白文字の省略可能です。Optional white space. 先頭に空白文字を表示できるs場合styleが含まれています、NumberStyles.AllowLeadingWhiteフラグ、または末尾のs場合styleが含まれています、NumberStyles.AllowTrailingWhiteフラグ。White space can appear at the beginning of s if style includes the NumberStyles.AllowLeadingWhite flag, or at the end of s if style includes the NumberStyles.AllowTrailingWhite flag.
$ カルチャ固有の通貨記号。A culture-specific currency symbol. によって、文字列内の位置が定義されている、NumberFormatInfo.CurrencyPositivePatternNumberFormatInfo.CurrencyNegativePattern現在のカルチャのプロパティ。Its position in the string is defined by the NumberFormatInfo.CurrencyPositivePattern and NumberFormatInfo.CurrencyNegativePattern property of the current culture. 現在のカルチャの通貨記号に表示されるs場合styleが含まれています、NumberStyles.AllowCurrencySymbolフラグ。The current culture's currency symbol can appear in s if style includes the NumberStyles.AllowCurrencySymbol flag.
signsign オプションの符号。An optional sign. 先頭の符号が表示できるs場合styleが含まれています、NumberStyles.AllowLeadingSignの最後に、フラグ、およびそれが表示されるs場合styleが含まれています、NumberStyles.AllowTrailingSignフラグ。The sign can appear at the beginning of s if style includes the NumberStyles.AllowLeadingSign flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingSign flag. かっこを使用できるs負の値を指定する場合styleが含まれています、NumberStyles.AllowParenthesesフラグ。Parentheses can be used in s to indicate a negative value if style includes the NumberStyles.AllowParentheses flag.
数字digits 0 ~ 9 桁の数字のシーケンス。A sequence of digits from 0 through 9.
, カルチャ固有の桁区切り記号。A culture-specific thousands separator symbol. 数千の現在のカルチャの区切り記号に表示されるs場合styleが含まれています、NumberStyles.AllowThousandsフラグ。The current culture's thousands separator symbol can appear in s if style includes the NumberStyles.AllowThousands flag.
.. カルチャに固有の小数点記号。A culture-specific decimal point symbol. 現在のカルチャの小数点記号に表示されるs場合styleが含まれています、NumberStyles.AllowDecimalPointフラグ。The current culture's decimal point symbol can appear in s if style includes the NumberStyles.AllowDecimalPoint flag.
fractional_digitsfractional_digits 0 の数字のシーケンス。A sequence of the 0 digit. 小数部の桁数を表示できるs場合styleが含まれています、NumberStyles.AllowDecimalPointフラグ。Fractional digits can appear in s if style includes the NumberStyles.AllowDecimalPoint flag. 0 以外の任意の数字が表示される場合fractional_digitsがスローされます、OverflowExceptionします。If any digit other than 0 appears in fractional_digits, the method throws an OverflowException.
ee "E"または"E"文字は、ことを示しますs指数表記で表すことができます。The 'e' or 'E' character, which indicates that s can be represented in exponential notation. sパラメーターは指数表記の数値を表すことができる場合styleが含まれています、NumberStyles.AllowExponentフラグ。The s parameter can represent a number in exponential notation if style includes the NumberStyles.AllowExponent flag. ただし、sパラメーターの範囲内の数を表す必要があります、Int16データ型で、0 以外の小数部を含めることはできません。However, the s parameter must represent a number in the range of the Int16 data type and cannot have a non-zero fractional component.
hexdigitshexdigits 0 ~ f、または f の 0 から 16 進数のシーケンスA sequence of hexadecimal digits from 0 through f, or 0 through F.

注意

終端の NUL (u+0000) 文字sの値に関係なく、解析操作では無視されますが、style引数。Any terminating NUL (U+0000) characters in s are ignored by the parsing operation, regardless of the value of the style argument.

String とのみ (に対応する、NumberStyles.Noneスタイル) 常に正常に解析します。A string with digits only (which corresponds to the NumberStyles.None style) always parses successfully. 残りのほとんどNumberStylesメンバーがありますが、この入力文字列内に存在する必要はありません要素を制御します。Most of the remaining NumberStyles members control elements that may be but are not required to be present in this input string. 次の表に示す個別NumberStylesメンバー内に存在する要素に影響を与えるsします。The following table indicates how individual NumberStyles members affect the elements that may be present in s.

非複合 NumberStyles 値Non-composite NumberStyles values 数字だけでなく s で許可されている要素Elements permitted in s in addition to digits
NumberStyles.None 10 進数字のみです。Decimal digits only.
NumberStyles.AllowDecimalPoint .The . fractional_digits要素。and fractional_digits elements. ただし、 fractional_digitsのみ 1 つまたは複数の 0 の数字で構成する必要がありますまたはOverflowExceptionがスローされます。However, fractional_digits must consist of only one or more 0 digits or an OverflowException is thrown.
NumberStyles.AllowExponent sパラメーターは、指数表記も使用できます。The s parameter can also use exponential notation.
NumberStyles.AllowLeadingWhite Wsの先頭にある要素sします。The ws element at the beginning of s.
NumberStyles.AllowTrailingWhite Wsの末尾にある要素sします。The ws element at the end of s.
NumberStyles.AllowLeadingSign 符号は、前に配置できますします。A sign can appear before digits.
NumberStyles.AllowTrailingSign 符号が後に表示できるします。A sign can appear after digits.
NumberStyles.AllowParentheses サインオン形式の数値を囲むかっこ内の要素。The sign element in the form of parentheses enclosing the numeric value.
NumberStyles.AllowThousands 要素。The , element.
NumberStyles.AllowCurrencySymbol $ 要素。The $ element.

場合、NumberStyles.AllowHexSpecifierフラグを使用すると、sプレフィックスなしの 16 進数の値の文字列形式を指定する必要があります。If the NumberStyles.AllowHexSpecifier flag is used, s must be the string representation of a hexadecimal value without a prefix. たとえば、"9AF3"が正常に解析しますが、"0x9AF3"はありません。For example, "9AF3" parses successfully, but "0x9AF3" does not. 他のフラグのみに存在することができるstyleNumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteします。The only other flags that can be present in style are NumberStyles.AllowLeadingWhite and NumberStyles.AllowTrailingWhite. (、NumberStyles列挙体には複合数値スタイル、 NumberStyles.HexNumber、空白文字の両方のフラグが含まれます)。(The NumberStyles enumeration has a composite number style, NumberStyles.HexNumber, that includes both white space flags.)

sで書式設定情報を使用してパラメーターを解析するNumberFormatInfoオブジェクトを現在のシステム カルチャが初期化されます。The s parameter is parsed using the formatting information in a NumberFormatInfo object that is initialized for the current system culture. 詳細については、「NumberFormatInfo.CurrentInfo」を参照してください。For more information, see NumberFormatInfo.CurrentInfo. 解析するs、特定のカルチャの書式情報を使用して、呼び出し、Int16.Parse(String, NumberStyles, IFormatProvider)メソッド。To parse s using the formatting information of a specific culture, call the Int16.Parse(String, NumberStyles, IFormatProvider) method.

こちらもご覧ください

Parse(String) Parse(String) Parse(String) Parse(String)

数値の文字列形式を、それと等価な 16 ビット符号付き整数に変換します。Converts the string representation of a number to its 16-bit signed integer equivalent.

public:
 static short Parse(System::String ^ s);
public static short Parse (string s);
static member Parse : string -> int16
Public Shared Function Parse (s As String) As Short

パラメーター

s
String String String String

変換する数値を含む文字列。A string containing a number to convert.

戻り値

s に格納されている数値と等しい 16 ビット符号付き整数。A 16-bit signed integer equivalent to the number contained in s.

例外

s が正しい形式ではありません。s is not in the correct format.

s は、MinValue 未満の数値か、MaxValue より大きい数値を表します。s represents a number less than MinValue or greater than MaxValue.

次の例では、文字列値を使用して 16 ビット符号付き整数値に変換する方法、Int16.Parse(String)メソッド。The following example demonstrates how to convert a string value into a 16-bit signed integer value using the Int16.Parse(String) method. 結果の整数値がコンソールに表示されます。The resulting integer value is then displayed to the console.

String^ value;
Int16 number;
   
value = " 12603 ";
try
{
   number = Int16::Parse(value);
   Console::WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException ^e)
{
   Console::WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", 
                      value);
}
   
value = " 16,054";
try
{
   number = Int16::Parse(value);
   Console::WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException ^e)
{
   Console::WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", 
                     value);
}
                           
value = " -17264";
try
{
   number = Int16::Parse(value);
   Console::WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException ^e)
{
   Console::WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", 
                      value);
}
// The example displays the following output to the console:
//       Converted ' 12603 ' to 12603.
//       Unable to convert ' 16,054' to a 16-bit signed integer.
//       Converted ' -17264' to -17264.      
string value;
short number;

value = " 12603 ";
try
{
   number = Int16.Parse(value);
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", 
                     value);
}

value = " 16,054";
try
{
   number = Int16.Parse(value);
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", 
                     value);
}
                        
value = " -17264";
try
{
   number = Int16.Parse(value);
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", 
                     value);
}
// The example displays the following output to the console:
//       Converted ' 12603 ' to 12603.
//       Unable to convert ' 16,054' to a 16-bit signed integer.
//       Converted ' -17264' to -17264.      
Dim value As String
Dim number As Short

value = " 12603 "
Try
   number = Short.Parse(value)
   Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", _
                     value)
End Try

value = " 16,054"
Try
   number = Short.Parse(value)
   Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", _
                     value)
End Try
                        
value = " -17264"
Try
   number = Short.Parse(value)
   Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", _
                     value)
End Try
' The example displays the following output to the console:
'       Converted ' 12603 ' to 12603.
'       Unable to convert ' 16,054' to a 16-bit signed integer.
'       Converted ' -17264' to -17264.      

注釈

sパラメーターには、フォームの番号が含まれています。The s parameter contains a number of the form:

[ws][サインイン] の数字 [ws][ws][sign]digits[ws]

角かっこ ([ および ]) 内の要素は省略可能です。Elements in square brackets ([ and ]) are optional. 次の表は、それぞれの要素の説明です。The following table describes each element.

要素Element 説明Description
wsws 空白文字の省略可能です。Optional white space.
signsign オプションの符号。An optional sign.
数字digits 0 から 9 までの数字のシーケンス。A sequence of digits ranging from 0 to 9.

sパラメーターを使用して解釈されますが、NumberStyles.Integerスタイル。The s parameter is interpreted using the NumberStyles.Integer style. 整数値の 10 進数字以外には、先頭と末尾の空白および先頭の符号のみを使用できます。In addition to the integer value's decimal digits, only leading and trailing spaces together with a leading sign are allowed. 使用可能なスタイル要素を明示的に定義するs、いずれかを使用して、Int16.Parse(String, NumberStyles)またはParseメソッド。To explicitly define the style elements that can be present in s, use either the Int16.Parse(String, NumberStyles) or the Parse method.

sで書式設定情報を使用してパラメーターを解析するNumberFormatInfoオブジェクトを現在のシステム カルチャが初期化されます。The s parameter is parsed using the formatting information in a NumberFormatInfo object that is initialized for the current system culture. 詳細については、「CurrentInfo」を参照してください。For more information, see CurrentInfo. 他のいくつかのカルチャの書式設定情報を使用して文字列を解析するには、使用、Int16.Parse(String, IFormatProvider)またはInt16.Parse(String, NumberStyles, IFormatProvider)メソッド。To parse a string using the formatting information of some other culture, use the Int16.Parse(String, IFormatProvider) or the Int16.Parse(String, NumberStyles, IFormatProvider) method.

こちらもご覧ください

Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider)

指定したカルチャに固有の書式による数値の文字列形式を、それと等価な 16 ビット符号付き整数に変換します。Converts the string representation of a number in a specified culture-specific format to its 16-bit signed integer equivalent.

public:
 static short Parse(System::String ^ s, IFormatProvider ^ provider);
public static short Parse (string s, IFormatProvider provider);
static member Parse : string * IFormatProvider -> int16
Public Shared Function Parse (s As String, provider As IFormatProvider) As Short

パラメーター

s
String String String String

変換する数値を含む文字列。A string containing a number to convert.

provider
IFormatProvider IFormatProvider IFormatProvider IFormatProvider

s に関するカルチャに固有の書式設定情報を提供する IFormatProviderAn IFormatProvider that supplies culture-specific formatting information about s.

戻り値

s で指定した数値と等しい 16 ビット符号付き整数。A 16-bit signed integer equivalent to the number specified in s.

例外

s が正しい形式ではありません。s is not in the correct format.

s は、MinValue 未満の数値か、MaxValue より大きい数値を表します。s represents a number less than MinValue or greater than MaxValue.

次の例の文字列形式を解析するInt16値で、Int16.Parse(String, IFormatProvider)メソッド。The following example parses string representations of Int16 values with the Int16.Parse(String, IFormatProvider) method.

String^ stringToConvert;
Int16 number;

stringToConvert = " 214 ";
try
{
   number = Int16::Parse(stringToConvert, CultureInfo::InvariantCulture);
   Console::WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException ^e)
{
   Console::WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException ^e)
{
   Console::WriteLine("'{0'} is out of range of the Int16 data type.", 
                     stringToConvert);
}

stringToConvert = " + 214";                     
try
{
   number = Int16::Parse(stringToConvert, CultureInfo::InvariantCulture);
   Console::WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException ^e)
{
   Console::WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException ^e)
{
   Console::WriteLine("'{0'} is out of range of the Int16 data type.", 
                     stringToConvert);
}

stringToConvert = " +214 "; 
try
{
   number = Int16::Parse(stringToConvert, CultureInfo::InvariantCulture);
   Console::WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException ^e)
{
   Console::WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException ^e)
{
   Console::WriteLine("'{0'} is out of range of the Int16 data type.", 
                     stringToConvert);
}
// The example displays the following output to the console:
//       Converted ' 214 ' to 214.
//       Unable to parse ' + 214'.
//       Converted ' +214 ' to 214.
string stringToConvert;
short number;

stringToConvert = " 214 ";
try
{
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture);
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException)
{
   Console.WriteLine("'{0'} is out of range of the Int16 data type.", 
                     stringToConvert);
}

stringToConvert = " + 214";                     
try
{
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture);
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException)
{
   Console.WriteLine("'{0'} is out of range of the Int16 data type.", 
                     stringToConvert);
}

stringToConvert = " +214 "; 
try
{
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture);
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException)
{
   Console.WriteLine("'{0'} is out of range of the Int16 data type.", 
                     stringToConvert);
}
// The example displays the following output to the console:
//       Converted ' 214 ' to 214.
//       Unable to parse ' + 214'.
//       Converted ' +214 ' to 214.
Dim stringToConvert As String
Dim number As Short

stringToConvert = " 214 "
Try
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture)
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number)
Catch e As FormatException
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
   Console.WriteLine("'{0'} is out of range of the Int16 data type.", _
                     stringToConvert)
End Try

stringToConvert = " + 214"                                 
Try
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture)
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number)
Catch e As FormatException
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
   Console.WriteLine("'{0'} is out of range of the Int16 data type.", _
                     stringToConvert)
End Try

stringToConvert = " +214 " 
Try
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture)
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number)
Catch e As FormatException
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
   Console.WriteLine("'{0'} is out of range of the Int16 data type.", _
                     stringToConvert)
End Try
' The example displays the following output to the console:
'       Converted ' 214 ' to 214.
'       Unable to parse ' + 214'.
'       Converted ' +214 ' to 214.

注釈

sパラメーターには、フォームの番号が含まれています。The s parameter contains a number of the form:

[ws][サインイン] の数字 [ws][ws][sign]digits[ws]

角かっこ ([ および ]) 内の要素は省略可能です。Elements in square brackets ([ and ]) are optional. 次の表は、それぞれの要素の説明です。The following table describes each element.

要素Element 説明Description
wsws 省略可能な空白。An optional white space.
signsign オプションの符号。An optional sign.
数字digits 0 から 9 までの数字のシーケンス。A sequence of digits ranging from 0 to 9.

sパラメーターを使用して解釈されますが、NumberStyles.Integerスタイル。The s parameter is interpreted using the NumberStyles.Integer style. 10 進数字だけでなくは、先頭と末尾の空白および先頭の符号のみを許可します。sします。In addition to decimal digits, only leading and trailing spaces together with a leading sign are allowed in s. 使用できるカルチャに固有の書式情報とスタイル要素を明示的に定義するsを使用して、Int16.Parse(String, NumberStyles, IFormatProvider)メソッド。To explicitly define the style elements together with the culture-specific formatting information that can be present in s, use the Int16.Parse(String, NumberStyles, IFormatProvider) method.

providerパラメーターは、IFormatProvider実装を取得する、NumberFormatInfoオブジェクト。The provider parameter is an IFormatProvider implementation that obtains a NumberFormatInfo object. NumberFormatInfoの書式設定に関するカルチャ固有の情報を提供しますsします。The NumberFormatInfo provides culture-specific information about the format of s. 場合providernullNumberFormatInfo現在のカルチャが使用されます。If provider is null, the NumberFormatInfo for the current culture is used.

こちらもご覧ください

適用対象