This documentation is archived and is not being maintained.

Char.GetNumericValue Method (String, Int32)

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Shared Function GetNumericValue( _
   ByVal s As String, _
   ByVal index As Integer _
) As Double
public static double GetNumericValue(
 string s,
 int index
public: static double GetNumericValue(
 String* s,
 int index
public static function GetNumericValue(
   s : String,
 index : int
) : double;


A String.
The character position in s.

Return Value

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


Exception Type Condition
ArgumentNullException s is a null reference (Nothing in Visual Basic).
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.


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 categories in UnicodeCategory: DecimalDigitNumber, LetterNumber, or OtherNumber.


[Visual Basic, C#, C++] The following sample demonstrates GetNumericValue.

[Visual Basic] 
Imports System

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

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, 8));    // Output: "1"

#using <mscorlib.dll>
using namespace System;

int main() {
   String* str = "input: 1";

   Console::WriteLine(Char::GetNumericValue('8'));    // Output: "8"
   Console::WriteLine(Char::GetNumericValue(str, 7)); // Output: "1"

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

Char Structure | Char Members | System Namespace | Char.GetNumericValue Overload List