Char.GetNumericValue Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Egy megadott numerikus Unicode-karaktert kettős pontosságú lebegőpontos számmá alakít át.
Túlterhelések
| Name | Description |
|---|---|
| GetNumericValue(String, Int32) |
A megadott sztringben megadott pozícióban lévő numerikus Unicode-karaktert dupla pontosságú lebegőpontos számmá alakítja. |
| GetNumericValue(Char) |
A megadott numerikus Unicode-karaktert dupla pontosságú lebegőpontos számmá alakítja. |
GetNumericValue(String, Int32)
A megadott sztringben megadott pozícióban lévő numerikus Unicode-karaktert dupla pontosságú lebegőpontos számmá alakítja.
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
Paraméterek
- index
- Int32
A karakter pozíciója a következőben s: .
Válaszok
A pozícióban s lévő index karakter numerikus értéke, ha ez a karakter egy számot jelöl, ellenkező esetben -1.
Kivételek
s az null.
index kisebb, mint nulla vagy nagyobb, mint az utolsó pozíció a nézetben s.
Példák
Az alábbi példakód bemutatja.GetNumericValue
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"
}
}
open System
let str = "input: 1"
printfn $"{Char.GetNumericValue '8'}" // Output: "8"
printfn $"{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
Megjegyzések
A s paraméternek egy numerikus érték sztring-ábrázolásának kell lennie. Ha például a pozícióban index lévő s karakter "5", akkor a visszatérési érték 5. Ha azonban a pozícióban index lévő s karakter "z", akkor a visszatérési érték -1.
A sztring karakterpozíciói nullától kezdve indexelhetők.
Egy karakter akkor és csak akkor rendelkezik numerikus értékkel, ha az a következő UnicodeCategory kategóriák egyikének tagja: DecimalDigitNumber, LetterNumbervagy OtherNumber.
Ha a Char pozícióban index lévő objektum egy érvényes helyettesítő pár első karaktere, a GetNumericValue(String, Int32) módszer meghatározza, hogy a helyettesítő pár numerikus számjegyet alkot-e. Az égei számozási rendszer például az U+10107–U+10133 kódpontokból áll. Az alábbi példa az egyes égei számokat képviselő sztringek példányosítására használja a ConvertFromUtf32 metódust. Ahogy a példa kimenete is mutatja, a GetNumericValue(String, Int32) metódus a megfelelő numerikus értéket adja vissza, ha egy égei szám magas helyettesítője lesz. Azonban, ha át az alacsony helyettes, úgy véli, csak az alacsony helyettes elszigetelten, és visszatér -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 in 0x10107..0x10133 do
let surrogate = Char.ConvertFromUtf32 utf32
for i = 0 to surrogate.Length - 1 do
printf $"U+{Convert.ToUInt16 surrogate[i]:X4} at position {i}: {Char.GetNumericValue(surrogate, i)} "
printfn ""
// 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
A következőre érvényes:
GetNumericValue(Char)
A megadott numerikus Unicode-karaktert dupla pontosságú lebegőpontos számmá alakítja.
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
Paraméterek
- c
- Char
Az átalakítandó Unicode-karakter.
Válaszok
Ha ez a c karakter számérték, ellenkező esetben -1,0.
Példák
Az alábbi példa bemutatja.GetNumericValue
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"
}
}
open System
let str = "input: 1"
printfn $"{Char.GetNumericValue '8'}" // Output: "8"
printfn $"{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
Megjegyzések
A c paraméternek numerikus Char értéknek kell lennie. Ha például c "5", akkor a visszatérési érték 5. Ha c azonban "z", akkor a visszatérési érték -1,0.
Egy karakter akkor és csak akkor rendelkezik numerikus értékkel, ha az a következő UnicodeCategory kategóriák egyikének tagja: DecimalDigitNumber, LetterNumbervagy OtherNumber.
A GetNumericValue módszer feltételezi, hogy c egyetlen nyelvi karakternek felel meg, és ellenőrzi, hogy ez a karakter decimális számjegygé alakítható-e. A Unicode-szabvány egyes számait azonban két Char olyan objektum jelöli, amelyek helyettesítő párokat alkotnak. Az égei számozási rendszer például az U+10107–U+10133 kódpontokból áll. Az alábbi példa az AEGEAN 1. számú sztringjének példányosítására használja a ConvertFromUtf32 metódust. Ahogy a példa kimenete is mutatja, a GetNumericValue(Char) metódus -1 ad vissza, ha magas helyettesítő vagy alacsony helyettesítő karaktert ad át.
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
let utf32 = 0x10107 // AEGEAN NUMBER ONE
let surrogate = Char.ConvertFromUtf32 utf32
for ch in surrogate do
printfn $"U+{Convert.ToUInt16 ch:X4}: {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