Char.GetNumericValue Char.GetNumericValue Char.GetNumericValue Char.GetNumericValue Method

定義

指定された Unicode 文字の数字を倍精度浮動小数点数に変換します。Converts a specified numeric Unicode character to a double-precision floating-point number.

オーバーロード

GetNumericValue(String, Int32) GetNumericValue(String, Int32) GetNumericValue(String, Int32) GetNumericValue(String, Int32)

指定した文字列の指定位置にある Unicode の数字を倍精度浮動小数点数に変換します。Converts the numeric Unicode character at the specified position in a specified string to a double-precision floating point number.

GetNumericValue(Char) GetNumericValue(Char) GetNumericValue(Char) GetNumericValue(Char)

指定された Unicode の数字を倍精度浮動小数点数に変換します。Converts the specified numeric Unicode character to a double-precision floating point number.

GetNumericValue(String, Int32) GetNumericValue(String, Int32) GetNumericValue(String, Int32) GetNumericValue(String, Int32)

指定した文字列の指定位置にある Unicode の数字を倍精度浮動小数点数に変換します。Converts the numeric Unicode character at the specified position in a specified string to a double-precision floating point number.

public:
 static double GetNumericValue(System::String ^ s, int index);
public static double GetNumericValue (string s, int index);
static member GetNumericValue : string * int -> double
Public Shared Function GetNumericValue (s As String, index As Integer) As Double

パラメーター

index
Int32 Int32 Int32 Int32

s 内の文字位置。The character position in s.

戻り値

この文字が数字の場合は、indexs の位置のこの文字の数値。それ以外の場合は -1。The numeric value of the character at position index in s if that character represents a number; otherwise, -1.

例外

index が 0 未満の値か、s の最後の位置より大きい値です。index is less than zero or greater than the last position in s.

次のコード例でGetNumericValueは、を示します。The following code example demonstrates GetNumericValue.

using namespace System;
int main()
{
   String^ str =  "input: 1";
   Console::WriteLine( Char::GetNumericValue( '8' ) ); // Output: "8"
   Console::WriteLine( Char::GetNumericValue( str, 7 ) ); // Output: "1"
}

using System;

public class GetNumericValueSample {
	public static void Main() {
		string str = "input: 1";

		Console.WriteLine(Char.GetNumericValue('8'));		// Output: "8"
		Console.WriteLine(Char.GetNumericValue(str, 7));	// Output: "1"
	}
}
Module GetNumericValueSample
    Sub Main()
        Dim str As String
        str = "input: 1"

        Console.WriteLine(Char.GetNumericValue("8"c))       ' Output: "8"
        Console.WriteLine(Char.GetNumericValue(str, 7))     ' Output: "1"
    End Sub
End Module

注釈

パラメーター sは、数値の文字列形式である必要があります。The s parameter must be the string representation of a numeric value. たとえば、ののindex s位置にある文字が "5" の場合、戻り値は5になります。For example, if the character at position index in s is "5", the return value is 5. ただし、ののindex s位置にある文字が "z" の場合、戻り値は-1 になります。However, if the character at position index in s is "z", the return value is -1.

文字列内の文字位置は0から始まるインデックスが作成されます。Character positions in a string are indexed starting from zero.

文字にはUnicodeCategory 、、 LetterNumber、またはOtherNumberのいずれかのカテゴリのメンバーである場合にのみ、関連DecimalDigitNumber付けられた数値が含まれます。A character has an associated numeric value if and only if it is a member of one of the following UnicodeCategory categories: DecimalDigitNumber, LetterNumber, or OtherNumber.

Char位置GetNumericValue(String, Int32)にあるオブジェクトが有効なサロゲートペアの最初の文字である場合、メソッドは、サロゲートペアが数字を形成するかどうかを判断します。 indexIf the Char object at position index is the first character of a valid surrogate pair, the GetNumericValue(String, Int32) method determines whether the surrogate pair forms a numeric digit. たとえば、Aegean ナンバリングシステムは、コードポイント U + 10107 から U + 10133 で構成されます。For example, the Aegean numbering system consists of code points U+10107 through U+10133. 次の例ではConvertFromUtf32 、メソッドを使用して、各 Aegean 番号を表す文字列をインスタンス化します。The following example uses the ConvertFromUtf32 method to instantiate a string that represents each Aegean number. この例の出力結果が示すようにGetNumericValue(String, Int32) 、Aegean number の上位サロゲートが渡された場合、メソッドは正しい数値を返します。As the output from the example shows, the GetNumericValue(String, Int32) method returns the correct numeric value if it is passed the high surrogate of an Aegean number. ただし、下位サロゲートを渡すと、下位サロゲートのみが分離され、-1 が返されます。However, if it is passed the low surrogate, it considers only the low surrogate in isolation and returns -1.

// Define a UTF32 value for each character in the 
// Aegean numbering system.
for (int utf32 = 0x10107; utf32 <= 0x10133; utf32++) {
   string surrogate = Char.ConvertFromUtf32(utf32);
   for (int ctr = 0; ctr < surrogate.Length; ctr++) 
      Console.Write("U+{0:X4} at position {1}: {2}     ", 
                        Convert.ToUInt16(surrogate[ctr]), ctr,  
                        Char.GetNumericValue(surrogate, ctr));

   Console.WriteLine();
}    
// The example displays the following output:
//       U+D800 at position 0: 1     U+DD07 at position 1: -1
//       U+D800 at position 0: 2     U+DD08 at position 1: -1
//       U+D800 at position 0: 3     U+DD09 at position 1: -1
//       U+D800 at position 0: 4     U+DD0A at position 1: -1
//       U+D800 at position 0: 5     U+DD0B at position 1: -1
//       U+D800 at position 0: 6     U+DD0C at position 1: -1
//       U+D800 at position 0: 7     U+DD0D at position 1: -1
//       U+D800 at position 0: 8     U+DD0E at position 1: -1
//       U+D800 at position 0: 9     U+DD0F at position 1: -1
//       U+D800 at position 0: 10     U+DD10 at position 1: -1
//       U+D800 at position 0: 20     U+DD11 at position 1: -1
//       U+D800 at position 0: 30     U+DD12 at position 1: -1
//       U+D800 at position 0: 40     U+DD13 at position 1: -1
//       U+D800 at position 0: 50     U+DD14 at position 1: -1
//       U+D800 at position 0: 60     U+DD15 at position 1: -1
//       U+D800 at position 0: 70     U+DD16 at position 1: -1
//       U+D800 at position 0: 80     U+DD17 at position 1: -1
//       U+D800 at position 0: 90     U+DD18 at position 1: -1
//       U+D800 at position 0: 100     U+DD19 at position 1: -1
//       U+D800 at position 0: 200     U+DD1A at position 1: -1
//       U+D800 at position 0: 300     U+DD1B at position 1: -1
//       U+D800 at position 0: 400     U+DD1C at position 1: -1
//       U+D800 at position 0: 500     U+DD1D at position 1: -1
//       U+D800 at position 0: 600     U+DD1E at position 1: -1
//       U+D800 at position 0: 700     U+DD1F at position 1: -1
//       U+D800 at position 0: 800     U+DD20 at position 1: -1
//       U+D800 at position 0: 900     U+DD21 at position 1: -1
//       U+D800 at position 0: 1000     U+DD22 at position 1: -1
//       U+D800 at position 0: 2000     U+DD23 at position 1: -1
//       U+D800 at position 0: 3000     U+DD24 at position 1: -1
//       U+D800 at position 0: 4000     U+DD25 at position 1: -1
//       U+D800 at position 0: 5000     U+DD26 at position 1: -1
//       U+D800 at position 0: 6000     U+DD27 at position 1: -1
//       U+D800 at position 0: 7000     U+DD28 at position 1: -1
//       U+D800 at position 0: 8000     U+DD29 at position 1: -1
//       U+D800 at position 0: 9000     U+DD2A at position 1: -1
//       U+D800 at position 0: 10000     U+DD2B at position 1: -1
//       U+D800 at position 0: 20000     U+DD2C at position 1: -1
//       U+D800 at position 0: 30000     U+DD2D at position 1: -1
//       U+D800 at position 0: 40000     U+DD2E at position 1: -1
//       U+D800 at position 0: 50000     U+DD2F at position 1: -1
//       U+D800 at position 0: 60000     U+DD30 at position 1: -1
//       U+D800 at position 0: 70000     U+DD31 at position 1: -1
//       U+D800 at position 0: 80000     U+DD32 at position 1: -1
//       U+D800 at position 0: 90000     U+DD33 at position 1: -1
' Define a UTF32 value for each character in the 
' Aegean numbering system.
For utf32 As Integer = &h10107 To &h10133
   Dim surrogate As String = Char.ConvertFromUtf32(utf32)
   For ctr As Integer = 0 To surrogate.Length - 1
      Console.Write("U+{0:X4} at position {1}: {2}     ", 
                        Convert.ToUInt16(surrogate(ctr)), ctr,  
                        Char.GetNumericValue(surrogate, ctr))
   Next
   Console.WriteLine()
Next    
' The example displays the following output:
'       U+D800 at position 0: 1     U+DD07 at position 1: -1
'       U+D800 at position 0: 2     U+DD08 at position 1: -1
'       U+D800 at position 0: 3     U+DD09 at position 1: -1
'       U+D800 at position 0: 4     U+DD0A at position 1: -1
'       U+D800 at position 0: 5     U+DD0B at position 1: -1
'       U+D800 at position 0: 6     U+DD0C at position 1: -1
'       U+D800 at position 0: 7     U+DD0D at position 1: -1
'       U+D800 at position 0: 8     U+DD0E at position 1: -1
'       U+D800 at position 0: 9     U+DD0F at position 1: -1
'       U+D800 at position 0: 10     U+DD10 at position 1: -1
'       U+D800 at position 0: 20     U+DD11 at position 1: -1
'       U+D800 at position 0: 30     U+DD12 at position 1: -1
'       U+D800 at position 0: 40     U+DD13 at position 1: -1
'       U+D800 at position 0: 50     U+DD14 at position 1: -1
'       U+D800 at position 0: 60     U+DD15 at position 1: -1
'       U+D800 at position 0: 70     U+DD16 at position 1: -1
'       U+D800 at position 0: 80     U+DD17 at position 1: -1
'       U+D800 at position 0: 90     U+DD18 at position 1: -1
'       U+D800 at position 0: 100     U+DD19 at position 1: -1
'       U+D800 at position 0: 200     U+DD1A at position 1: -1
'       U+D800 at position 0: 300     U+DD1B at position 1: -1
'       U+D800 at position 0: 400     U+DD1C at position 1: -1
'       U+D800 at position 0: 500     U+DD1D at position 1: -1
'       U+D800 at position 0: 600     U+DD1E at position 1: -1
'       U+D800 at position 0: 700     U+DD1F at position 1: -1
'       U+D800 at position 0: 800     U+DD20 at position 1: -1
'       U+D800 at position 0: 900     U+DD21 at position 1: -1
'       U+D800 at position 0: 1000     U+DD22 at position 1: -1
'       U+D800 at position 0: 2000     U+DD23 at position 1: -1
'       U+D800 at position 0: 3000     U+DD24 at position 1: -1
'       U+D800 at position 0: 4000     U+DD25 at position 1: -1
'       U+D800 at position 0: 5000     U+DD26 at position 1: -1
'       U+D800 at position 0: 6000     U+DD27 at position 1: -1
'       U+D800 at position 0: 7000     U+DD28 at position 1: -1
'       U+D800 at position 0: 8000     U+DD29 at position 1: -1
'       U+D800 at position 0: 9000     U+DD2A at position 1: -1
'       U+D800 at position 0: 10000     U+DD2B at position 1: -1
'       U+D800 at position 0: 20000     U+DD2C at position 1: -1
'       U+D800 at position 0: 30000     U+DD2D at position 1: -1
'       U+D800 at position 0: 40000     U+DD2E at position 1: -1
'       U+D800 at position 0: 50000     U+DD2F at position 1: -1
'       U+D800 at position 0: 60000     U+DD30 at position 1: -1
'       U+D800 at position 0: 70000     U+DD31 at position 1: -1
'       U+D800 at position 0: 80000     U+DD32 at position 1: -1
'       U+D800 at position 0: 90000     U+DD33 at position 1: -1

GetNumericValue(Char) GetNumericValue(Char) GetNumericValue(Char) GetNumericValue(Char)

指定された Unicode の数字を倍精度浮動小数点数に変換します。Converts the specified numeric Unicode character to a double-precision floating point number.

public:
 static double GetNumericValue(char c);
public static double GetNumericValue (char c);
static member GetNumericValue : char -> double
Public Shared Function GetNumericValue (c As Char) As Double

パラメーター

c
Char Char Char Char

変換する Unicode 文字。The Unicode character to convert.

戻り値

この文字が数字を表す場合は c の数値。それ以外の場合は -1.0。The numeric value of c if that character represents a number; otherwise, -1.0.

次の例はGetNumericValue、を示しています。The following example demonstrates GetNumericValue.

using namespace System;
int main()
{
   String^ str =  "input: 1";
   Console::WriteLine( Char::GetNumericValue( '8' ) ); // Output: "8"
   Console::WriteLine( Char::GetNumericValue( str, 7 ) ); // Output: "1"
}

using System;

public class GetNumericValueSample {
	public static void Main() {
		string str = "input: 1";

		Console.WriteLine(Char.GetNumericValue('8'));		// Output: "8"
		Console.WriteLine(Char.GetNumericValue(str, 7));	// Output: "1"
	}
}
Module GetNumericValueSample
    Sub Main()
        Dim str As String
        str = "input: 1"

        Console.WriteLine(Char.GetNumericValue("8"c))       ' Output: "8"
        Console.WriteLine(Char.GetNumericValue(str, 7))     ' Output: "1"
    End Sub
End Module

注釈

パラメーター cは数値のChar表現である必要があります。The c parameter must be the Char representation of a numeric value. たとえば、が " c 5" の場合、戻り値は5です。For example, if c is "5", the return value is 5. ただし、がc "z" の場合、戻り値は-1.0 です。However, if c is "z", the return value is -1.0.

文字にはUnicodeCategory 、、 LetterNumber、またはOtherNumberのいずれかのカテゴリのメンバーである場合にのみ、関連DecimalDigitNumber付けられた数値が含まれます。A character has an associated numeric value if and only if it is a member of one of the following UnicodeCategory categories: DecimalDigitNumber, LetterNumber, or OtherNumber.

メソッドGetNumericValueは、がc 1 つの言語の文字に対応し、その文字が10進数に変換できるかどうかをチェックします。The GetNumericValue method assumes that c corresponds to a single linguistic character and checks whether that character can be converted to a decimal digit. ただし、Unicode 規格の一部の数値は、サロゲートペアCharを形成する2つのオブジェクトによって表されます。However, some numbers in the Unicode standard are represented by two Char objects that form a surrogate pair. たとえば、Aegean ナンバリングシステムは、コードポイント U + 10107 から U + 10133 で構成されます。For example, the Aegean numbering system consists of code points U+10107 through U+10133. 次の例ではConvertFromUtf32 、メソッドを使用して、AEGEAN NUMBER ONE を表す文字列をインスタンス化します。The following example uses the ConvertFromUtf32 method to instantiate a string that represents AEGEAN NUMBER ONE. この例の出力結果が示すようにGetNumericValue(Char) 、この文字の上位サロゲートまたは下位サロゲートが渡された場合、このメソッドは-1 を返します。As the output from the example shows, the GetNumericValue(Char) method returns -1 if it is passed either a high surrogate or a low surrogate of this character.

int utf32 = 0x10107;       // AEGEAN NUMBER ONE
string surrogate = Char.ConvertFromUtf32(utf32);
foreach (var ch in surrogate)
   Console.WriteLine("U+{0:X4}: {1}    ", Convert.ToUInt16(ch), 
                                          Char.GetNumericValue(ch));

// The example displays the following output:
//       U+D800: -1
//       U+DD07: -1
Dim utf32 As Integer = &h10107       ' AEGEAN NUMBER ONE
Dim surrogate As String = Char.ConvertFromUtf32(utf32)
For Each ch In surrogate
   Console.WriteLine("U+{0:X4}: {1}    ", Convert.ToUInt16(ch), 
                                          Char.GetNumericValue(ch))
Next
' The example displays the following output:
'       U+D800: -1
'       U+DD07: -1

適用対象