Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Char::GetNumericValue Method (String^, Int32)

 

Converts the numeric Unicode character at the specified position in a specified string to a double-precision floating point number.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public:
static double GetNumericValue(
	String^ s,
	int index
)

Parameters

s
Type: System::String^

A String.

index
Type: System::Int32

The character position in s.

Return Value

Type: System::Double

The numeric value of the character at position index in s if that character represents a number; otherwise, -1.

Exception Condition
ArgumentNullException

s is null.

ArgumentOutOfRangeException

index is less than zero or greater than the last position in s.

The s parameter must be the string representation of a numeric value. For example, if the character at position index in s is "5", the return value is 5. However, if the character at position index in s is "z", the return value is -1.

Character positions in a string are indexed starting from zero.

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.

If 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. 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(String^, Int32) 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.

No code example is currently available or this language may not be supported.

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"
}

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: