CharUnicodeInfo.GetDecimalDigitValue 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得數字 Unicode 字元的十進位數值。
多載
GetDecimalDigitValue(Char) |
取得指定之數字字元的十進位數值。 |
GetDecimalDigitValue(String, Int32) |
取得數字字元的十進位數值,其位於指定字串的指定索引處。 |
GetDecimalDigitValue(Char)
取得指定之數字字元的十進位數值。
public:
static int GetDecimalDigitValue(char ch);
public static int GetDecimalDigitValue (char ch);
static member GetDecimalDigitValue : char -> int
Public Shared Function GetDecimalDigitValue (ch As Char) As Integer
參數
- ch
- Char
要取得十進位數值的 Unicode 字元。
傳回
指定之數字字元的十進位數值。
-或-
如果指定的字元不是十進位數字,則為 -1。
範例
下列程式代碼範例顯示每個方法針對不同類型的字元所傳回的值。
using namespace System;
using namespace System::Globalization;
void PrintProperties( Char c );
int main()
{
Console::WriteLine( " c Num Dig Dec UnicodeCategory" );
Console::Write( "U+0061 LATIN SMALL LETTER A " );
PrintProperties( L'a' );
Console::Write( "U+0393 GREEK CAPITAL LETTER GAMMA " );
PrintProperties( L'\u0393' );
Console::Write( "U+0039 DIGIT NINE " );
PrintProperties( L'9' );
Console::Write( "U+00B2 SUPERSCRIPT TWO " );
PrintProperties( L'\u00B2' );
Console::Write( "U+00BC VULGAR FRACTION ONE QUARTER " );
PrintProperties( L'\u00BC' );
Console::Write( "U+0BEF TAMIL DIGIT NINE " );
PrintProperties( L'\u0BEF' );
Console::Write( "U+0BF0 TAMIL NUMBER TEN " );
PrintProperties( L'\u0BF0' );
Console::Write( "U+0F33 TIBETAN DIGIT HALF ZERO " );
PrintProperties( L'\u0F33' );
Console::Write( "U+2788 CIRCLED SANS-SERIF DIGIT NINE " );
PrintProperties( L'\u2788' );
}
void PrintProperties( Char c )
{
Console::Write( " {0,-3}", c );
Console::Write( " {0,-5}", CharUnicodeInfo::GetNumericValue( c ) );
Console::Write( " {0,-5}", CharUnicodeInfo::GetDigitValue( c ) );
Console::Write( " {0,-5}", CharUnicodeInfo::GetDecimalDigitValue( c ) );
Console::WriteLine( "{0}", CharUnicodeInfo::GetUnicodeCategory( c ) );
}
/*
This code produces the following output. Some characters might not display at the console.
c Num Dig Dec UnicodeCategory
U+0061 LATIN SMALL LETTER A a -1 -1 -1 LowercaseLetter
U+0393 GREEK CAPITAL LETTER GAMMA Γ -1 -1 -1 UppercaseLetter
U+0039 DIGIT NINE 9 9 9 9 DecimalDigitNumber
U+00B2 SUPERSCRIPT TWO ² 2 2 -1 OtherNumber
U+00BC VULGAR FRACTION ONE QUARTER ¼ 0.25 -1 -1 OtherNumber
U+0BEF TAMIL DIGIT NINE ௯ 9 9 9 DecimalDigitNumber
U+0BF0 TAMIL NUMBER TEN ௰ 10 -1 -1 OtherNumber
U+0F33 TIBETAN DIGIT HALF ZERO ༳ -0.5 -1 -1 OtherNumber
U+2788 CIRCLED SANS-SERIF DIGIT NINE ➈ 9 9 -1 OtherNumber
*/
using System;
using System.Globalization;
public class SamplesCharUnicodeInfo {
public static void Main() {
Console.WriteLine( " c Num Dig Dec UnicodeCategory" );
Console.Write( "U+0061 LATIN SMALL LETTER A " );
PrintProperties( 'a' );
Console.Write( "U+0393 GREEK CAPITAL LETTER GAMMA " );
PrintProperties( '\u0393' );
Console.Write( "U+0039 DIGIT NINE " );
PrintProperties( '9' );
Console.Write( "U+00B2 SUPERSCRIPT TWO " );
PrintProperties( '\u00B2' );
Console.Write( "U+00BC VULGAR FRACTION ONE QUARTER " );
PrintProperties( '\u00BC' );
Console.Write( "U+0BEF TAMIL DIGIT NINE " );
PrintProperties( '\u0BEF' );
Console.Write( "U+0BF0 TAMIL NUMBER TEN " );
PrintProperties( '\u0BF0' );
Console.Write( "U+0F33 TIBETAN DIGIT HALF ZERO " );
PrintProperties( '\u0F33' );
Console.Write( "U+2788 CIRCLED SANS-SERIF DIGIT NINE " );
PrintProperties( '\u2788' );
}
public static void PrintProperties( char c ) {
Console.Write( " {0,-3}", c );
Console.Write( " {0,-5}", CharUnicodeInfo.GetNumericValue( c ) );
Console.Write( " {0,-5}", CharUnicodeInfo.GetDigitValue( c ) );
Console.Write( " {0,-5}", CharUnicodeInfo.GetDecimalDigitValue( c ) );
Console.WriteLine( "{0}", CharUnicodeInfo.GetUnicodeCategory( c ) );
}
}
/*
This code produces the following output. Some characters might not display at the console.
c Num Dig Dec UnicodeCategory
U+0061 LATIN SMALL LETTER A a -1 -1 -1 LowercaseLetter
U+0393 GREEK CAPITAL LETTER GAMMA Γ -1 -1 -1 UppercaseLetter
U+0039 DIGIT NINE 9 9 9 9 DecimalDigitNumber
U+00B2 SUPERSCRIPT TWO ² 2 2 -1 OtherNumber
U+00BC VULGAR FRACTION ONE QUARTER ¼ 0.25 -1 -1 OtherNumber
U+0BEF TAMIL DIGIT NINE ௯ 9 9 9 DecimalDigitNumber
U+0BF0 TAMIL NUMBER TEN ௰ 10 -1 -1 OtherNumber
U+0F33 TIBETAN DIGIT HALF ZERO ༳ -0.5 -1 -1 OtherNumber
U+2788 CIRCLED SANS-SERIF DIGIT NINE ➈ 9 9 -1 OtherNumber
*/
Imports System.Globalization
Public Class SamplesCharUnicodeInfo
Public Shared Sub Main()
Console.WriteLine(" c Num Dig Dec UnicodeCategory")
Console.Write("U+0061 LATIN SMALL LETTER A ")
PrintProperties("a"c)
Console.Write("U+0393 GREEK CAPITAL LETTER GAMMA ")
PrintProperties(ChrW(&H0393))
Console.Write("U+0039 DIGIT NINE ")
PrintProperties("9"c)
Console.Write("U+00B2 SUPERSCRIPT TWO ")
PrintProperties(ChrW(&H00B2))
Console.Write("U+00BC VULGAR FRACTION ONE QUARTER ")
PrintProperties(ChrW(&H00BC))
Console.Write("U+0BEF TAMIL DIGIT NINE ")
PrintProperties(ChrW(&H0BEF))
Console.Write("U+0BF0 TAMIL NUMBER TEN ")
PrintProperties(ChrW(&H0BF0))
Console.Write("U+0F33 TIBETAN DIGIT HALF ZERO ")
PrintProperties(ChrW(&H0F33))
Console.Write("U+2788 CIRCLED SANS-SERIF DIGIT NINE ")
PrintProperties(ChrW(&H2788))
End Sub
Public Shared Sub PrintProperties(c As Char)
Console.Write(" {0,-3}", c)
Console.Write(" {0,-5}", CharUnicodeInfo.GetNumericValue(c))
Console.Write(" {0,-5}", CharUnicodeInfo.GetDigitValue(c))
Console.Write(" {0,-5}", CharUnicodeInfo.GetDecimalDigitValue(c))
Console.WriteLine("{0}", CharUnicodeInfo.GetUnicodeCategory(c))
End Sub
End Class
'This code produces the following output. Some characters might not display at the console.
'
' c Num Dig Dec UnicodeCategory
'U+0061 LATIN SMALL LETTER A a -1 -1 -1 LowercaseLetter
'U+0393 GREEK CAPITAL LETTER GAMMA Γ -1 -1 -1 UppercaseLetter
'U+0039 DIGIT NINE 9 9 9 9 DecimalDigitNumber
'U+00B2 SUPERSCRIPT TWO ² 2 2 -1 OtherNumber
'U+00BC VULGAR FRACTION ONE QUARTER ¼ 0.25 -1 -1 OtherNumber
'U+0BEF TAMIL DIGIT NINE ௯ 9 9 9 DecimalDigitNumber
'U+0BF0 TAMIL NUMBER TEN ௰ 10 -1 -1 OtherNumber
'U+0F33 TIBETAN DIGIT HALF ZERO ༳ -0.5 -1 -1 OtherNumber
'U+2788 CIRCLED SANS-SERIF DIGIT NINE ➈ 9 9 -1 OtherNumber
備註
這個方法會將代表十進位數的字元轉換成其相等的整數值。 十進位數是類別中的 DecimalDigitNumber 字元,可代表 decimal (base 10) 編號系統的十位數之一,從零到 9。 它包含U+0030 (DIGIT ZERO) 到 U+0039 (DIGIT NINE) 、U+0660 (ARABIC-INDIC DIGIT ZERO) 到 U+0669 (ARABIC-INDIC DIGIT NINE) 等字元。 U+07C0 (NKO DIGIT ZERO) 到 U+07C9 (NKO DIGIT NINE) ,U+1040 () 到 U+1049 ( (位數 NINE) 。
如需 Unicode 字元的詳細資訊,請參閱 Unicode Standard。
適用於
GetDecimalDigitValue(String, Int32)
取得數字字元的十進位數值,其位於指定字串的指定索引處。
public:
static int GetDecimalDigitValue(System::String ^ s, int index);
public static int GetDecimalDigitValue (string s, int index);
static member GetDecimalDigitValue : string * int -> int
Public Shared Function GetDecimalDigitValue (s As String, index As Integer) As Integer
參數
- index
- Int32
要取得十進位數值之 Unicode 字元的索引。
傳回
數字字元的十進位數值,其位於指定字串的指定索引處。
-或-
如果位於指定字串之指定索引處的字元不是十進位數字,則為 -1。
例外狀況
s
為 null
。
index
在 s
的有效索引範圍之外。
範例
下列程式代碼範例顯示每個方法針對不同類型的字元所傳回的值。
using namespace System;
using namespace System::Globalization;
int main()
{
// The String to get information for.
String^ s = "a9\u0393\u00B2\u00BC\u0BEF\u0BF0\u2788";
Console::WriteLine( "String: {0}", s );
// Print the values for each of the characters in the string.
Console::WriteLine( "index c Num Dig Dec UnicodeCategory" );
for ( int i = 0; i < s->Length; i++ )
{
Console::Write( "{0,-5} {1,-3}", i, s[ i ] );
Console::Write( " {0,-5}", CharUnicodeInfo::GetNumericValue( s, i ) );
Console::Write( " {0,-5}", CharUnicodeInfo::GetDigitValue( s, i ) );
Console::Write( " {0,-5}", CharUnicodeInfo::GetDecimalDigitValue( s, i ) );
Console::WriteLine( "{0}", CharUnicodeInfo::GetUnicodeCategory( s, i ) );
}
}
/*
This code produces the following output. Some characters might not display at the console.
String: a9Γ²¼௯௰➈
index c Num Dig Dec UnicodeCategory
0 a -1 -1 -1 LowercaseLetter
1 9 9 9 9 DecimalDigitNumber
2 Γ -1 -1 -1 UppercaseLetter
3 ² 2 2 -1 OtherNumber
4 ¼ 0.25 -1 -1 OtherNumber
5 ௯ 9 9 9 DecimalDigitNumber
6 ௰ 10 -1 -1 OtherNumber
7 ➈ 9 9 -1 OtherNumber
*/
using System;
using System.Globalization;
public class SamplesCharUnicodeInfo {
public static void Main() {
// The String to get information for.
String s = "a9\u0393\u00B2\u00BC\u0BEF\u0BF0\u2788";
Console.WriteLine( "String: {0}", s );
// Print the values for each of the characters in the string.
Console.WriteLine( "index c Num Dig Dec UnicodeCategory" );
for ( int i = 0; i < s.Length; i++ ) {
Console.Write( "{0,-5} {1,-3}", i, s[i] );
Console.Write( " {0,-5}", CharUnicodeInfo.GetNumericValue( s, i ) );
Console.Write( " {0,-5}", CharUnicodeInfo.GetDigitValue( s, i ) );
Console.Write( " {0,-5}", CharUnicodeInfo.GetDecimalDigitValue( s, i ) );
Console.WriteLine( "{0}", CharUnicodeInfo.GetUnicodeCategory( s, i ) );
}
}
}
/*
This code produces the following output. Some characters might not display at the console.
String: a9Γ²¼௯௰➈
index c Num Dig Dec UnicodeCategory
0 a -1 -1 -1 LowercaseLetter
1 9 9 9 9 DecimalDigitNumber
2 Γ -1 -1 -1 UppercaseLetter
3 ² 2 2 -1 OtherNumber
4 ¼ 0.25 -1 -1 OtherNumber
5 ௯ 9 9 9 DecimalDigitNumber
6 ௰ 10 -1 -1 OtherNumber
7 ➈ 9 9 -1 OtherNumber
*/
Imports System.Globalization
Public Class SamplesCharUnicodeInfo
Public Shared Sub Main()
' The String to get information for.
Dim s As [String] = "a9\u0393\u00B2\u00BC\u0BEF\u0BF0\u2788"
Console.WriteLine("String: {0}", s)
' Print the values for each of the characters in the string.
Console.WriteLine("index c Num Dig Dec UnicodeCategory")
Dim i As Integer
For i = 0 To s.Length - 1
Console.Write("{0,-5} {1,-3}", i, s(i))
Console.Write(" {0,-5}", CharUnicodeInfo.GetNumericValue(s, i))
Console.Write(" {0,-5}", CharUnicodeInfo.GetDigitValue(s, i))
Console.Write(" {0,-5}", CharUnicodeInfo.GetDecimalDigitValue(s, i))
Console.WriteLine("{0}", CharUnicodeInfo.GetUnicodeCategory(s, i))
Next i
End Sub
End Class
'This code produces the following output. Some characters might not display at the console.
'
'String: a9Γ²¼௯௰➈
'index c Num Dig Dec UnicodeCategory
'0 a -1 -1 -1 LowercaseLetter
'1 9 9 9 9 DecimalDigitNumber
'2 Γ -1 -1 -1 UppercaseLetter
'3 ² 2 2 -1 OtherNumber
'4 ¼ 0.25 -1 -1 OtherNumber
'5 ௯ 9 9 9 DecimalDigitNumber
'6 ௰ 10 -1 -1 OtherNumber
'7 ➈ 9 9 -1 OtherNumber
備註
這個方法會將代表十進位數的字元轉換成其相等的整數值。 十進位數是類別中的 DecimalDigitNumber 字元,可代表 decimal (base 10) 編號系統的十位數之一,從零到 9。 它包含U+0030 (DIGIT ZERO) 到 U+0039 (DIGIT NINE) 、U+0660 (ARABIC-INDIC DIGIT ZERO) 到 U+0669 (ARABIC-INDIC DIGIT NINE) 等字元。 U+07C0 (NKO DIGIT ZERO) 到 U+07C9 (NKO DIGIT NINE) ,U+1040 () 到 U+1049 ( (位數 NINE) 。
如需 Unicode 字元的詳細資訊,請參閱 Unicode Standard。