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
)
public static double GetNumericValue (
	String s, 
	int index
)
public static function GetNumericValue (
	s : String, 
	index : int
) : double

Parameters

s

A String.

index

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 typeCondition

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.

The following code example demonstrates 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"
	}
}

import System.*;

public class GetNumericValueSample
{
    public static void main(String[] args)
    {
        String str = "input:  1";
      
        Console.WriteLine(Char.GetNumericValue('8')); // Output: "8"
        Console.WriteLine(Char.GetNumericValue(str, 8)); // Output: "1"
    } //main
} //GetNumericValueSample

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0
Show: