CharUnicodeInfo::GetNumericValue Method (String, Int32)
Gets the numeric value associated with the character at the specified index of the specified string.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- s
- Type: System::String
The String containing the Unicode character for which to get the numeric value.
- index
- Type: System::Int32
The index of the Unicode character for which to get the numeric value.
Return Value
Type: System::DoubleThe numeric value associated with the character at the specified index of the specified string.
-or-
-1, if the character at the specified index of the specified string is not a numeric character.
| Exception | Condition |
|---|---|
| ArgumentNullException | s is nullptr. |
| ArgumentOutOfRangeException | index is outside the range of valid indexes in s. |
Numeric value is a Unicode character property that applies only to numeric characters, which include fractions, subscripts, superscripts, Roman numerals, currency numerators, encircled numbers, and script-specific digits. For more information on Unicode characters, see the Unicode Standard.
If the Char object at position index is the first character of a valid surrogate pair, the GetNumericValue method determines whether the surrogate pair forms a numeric digit, and, if it does, returns its numeric value. For example, the Aegean numbering system consists of code points U+10107 through U+10133. The following example uses the ConvertFromUtf32 method to instantiate a string that represents each Aegean number. As the output from the example shows, the GetNumericValue method returns the correct numeric value if it is passed the high surrogate of an Aegean number. However, if it is passed the low surrogate, it considers only the low surrogate in isolation and returns -1.
The following code example shows the values returned by each method for different types of characters.
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\u0393\u00B2\u00BC\u0BEF\u0BF0\u2788 index c Num Dig Dec UnicodeCategory 0 a -1 -1 -1 LowercaseLetter 1 9 9 9 9 DecimalDigitNumber 2 \u0393 -1 -1 -1 UppercaseLetter 3 \u00B2 2 2 2 OtherNumber 4 \u00BC 0.25 -1 -1 OtherNumber 5 \u0BEF 9 9 9 DecimalDigitNumber 6 \u0BF0 10 -1 -1 OtherNumber 7 \u2788 9 9 -1 OtherNumber */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.