Char.IsNumber Metoda
Definicja
Wskazuje, czy znak Unicode jest kategoryzowany jako liczba.Indicates whether a Unicode character is categorized as a number.
Przeciążenia
IsNumber(Char) |
Wskazuje, czy określony znak Unicode jest kategoryzowany jako liczba.Indicates whether the specified Unicode character is categorized as a number. |
IsNumber(String, Int32) |
Wskazuje, czy znak w określonym położeniu w określonym ciągu jest kategoryzowany jako liczba.Indicates whether the character at the specified position in a specified string is categorized as a number. |
IsNumber(Char)
Wskazuje, czy określony znak Unicode jest kategoryzowany jako liczba.Indicates whether the specified Unicode character is categorized as a number.
public:
static bool IsNumber(char c);
public static bool IsNumber (char c);
static member IsNumber : char -> bool
Public Shared Function IsNumber (c As Char) As Boolean
Parametry
- c
- Char
Znak Unicode do oceny.The Unicode character to evaluate.
Zwraca
true
Jeśli c
jest liczbą; w przeciwnym razie false
.true
if c
is a number; otherwise, false
.
Przykłady
Poniższy przykład pokazuje IsNumber .The following example demonstrates IsNumber.
using namespace System;
int main()
{
String^ str = "non-numeric";
Console::WriteLine( Char::IsNumber( '8' ) ); // Output: "True"
Console::WriteLine( Char::IsNumber( str, 3 ) ); // Output: "False"
}
using System;
public class IsNumberSample {
public static void Main() {
string str = "non-numeric";
Console.WriteLine(Char.IsNumber('8')); // Output: "True"
Console.WriteLine(Char.IsNumber(str, 3)); // Output: "False"
}
}
Module IsNumberSample
Sub Main()
Dim str As String
str = "non-numeric"
Console.WriteLine(Char.IsNumber("8"c)) ' Output: "True"
Console.WriteLine(Char.IsNumber(str, 3)) ' Output: "False"
End Sub
End Module
Uwagi
Ta metoda określa, czy Char ma być dowolna numeryczna kategoria Unicode.This method determines whether a Char is of any numeric Unicode category. Oprócz dołączania cyfr, cyfry zawierają znaki, ułamki, indeksy dolne, nadindeksy, cyfry rzymskie, liczniki walutowe i liczby obstawne.In addition to including digits, numbers include characters, fractions, subscripts, superscripts, Roman numerals, currency numerators, and encircled numbers. Ta metoda różni się od IsDigit metody, która określa, czy Char jest to podstawy-10.This method contrasts with the IsDigit method, which determines whether a Char is a radix-10 digit.
Ważne
IsNumber(Char)Metoda nie jest przeznaczona do określenia, czy ciąg składa się ze znaków numerycznych (na przykład przez wywołanie metody dla każdego znaku w ciągu).The IsNumber(Char) method is not intended to determine whether a string consists of numeric characters (for example, by calling the method for each character in a string). Aby określić, czy ciąg składa się ze znaków numerycznych, wywołaj jedno z przeciążeń TryParse
metody (na przykład Int32.TryParse Double.TryParse typ całkowity lub zmiennoprzecinkowy).To determine whether a string consists of numeric characters, call one of the overloads of the TryParse
method (such as Int32.TryParse or Double.TryParse of an integral or floating point type.
Prawidłowe liczby to elementy należące do UnicodeCategory.DecimalDigitNumber UnicodeCategory.LetterNumber kategorii, lub UnicodeCategory.OtherNumber .Valid numbers are members of the UnicodeCategory.DecimalDigitNumber, UnicodeCategory.LetterNumber, or UnicodeCategory.OtherNumber category.
IsNumber(Char)Metoda zakłada, że c
odpowiada pojedynczym znakom językowym i sprawdza, czy ten znak reprezentuje liczbę.The IsNumber(Char) method assumes that c
corresponds to a single linguistic character and checks whether that character represents a number. Jednak niektóre liczby w standardzie Unicode są reprezentowane przez dwa Char obiekty tworzące parę zastępczą.However, some numbers in the Unicode standard are represented by two Char objects that form a surrogate pair. Na przykład system numeracji Morza Egejskiego składa się z kodów znaku U+10107 do U+10133.For example, the Aegean numbering system consists of code points U+10107 through U+10133. W poniższym przykładzie zastosowano ConvertFromUtf32 metodę w celu utworzenia wystąpienia ciągu reprezentującego numer Morza Egejskiego.The following example uses the ConvertFromUtf32 method to instantiate a string that represents AEGEAN NUMBER ONE. Ponieważ dane wyjściowe z przykładu są wyświetlane, IsNumber(Char) Metoda zwraca, false
Jeśli zostanie przekazana duża część lub niski Surogat tego znaku.As the output from the example shows, the IsNumber(Char) method returns false
if it is passed either a high surrogate or a low surrogate of this character.
int utf32 = 0x10107; // AEGEAN NUMBER ONE
string surrogate = Char.ConvertFromUtf32(utf32);
foreach (var ch in surrogate)
Console.WriteLine("U+{0:X4}: {1}", Convert.ToUInt16(ch),
Char.IsNumber(ch));
// The example displays the following output:
// U+D800: False
// U+DD07: False
Dim utf32 As Integer = &h10107 ' AEGEAN NUMBER ONE
Dim surrogate As String = Char.ConvertFromUtf32(utf32)
For Each ch In surrogate
Console.WriteLine("U+{0:X4}: {1}", Convert.ToUInt16(ch),
Char.IsNumber(ch))
Next
' The example displays the following output:
' U+D800: False
' U+DD07: False
Zobacz też
Dotyczy
IsNumber(String, Int32)
Wskazuje, czy znak w określonym położeniu w określonym ciągu jest kategoryzowany jako liczba.Indicates whether the character at the specified position in a specified string is categorized as a number.
public:
static bool IsNumber(System::String ^ s, int index);
public static bool IsNumber (string s, int index);
static member IsNumber : string * int -> bool
Public Shared Function IsNumber (s As String, index As Integer) As Boolean
Parametry
- s
- String
Ciąg.A string.
- index
- Int32
Pozycja znaku, który ma zostać obliczony s
.The position of the character to evaluate in s
.
Zwraca
true
Jeśli znak na pozycji index
w s
jest liczbą; w przeciwnym razie false
.true
if the character at position index
in s
is a number; otherwise, false
.
Wyjątki
s
to null
.s
is null
.
index
jest mniejsza od zera lub większa od ostatniej pozycji w s
.index
is less than zero or greater than the last position in s
.
Przykłady
Poniższy przykład pokazuje IsNumber .The following example demonstrates IsNumber.
using namespace System;
int main()
{
String^ str = "non-numeric";
Console::WriteLine( Char::IsNumber( '8' ) ); // Output: "True"
Console::WriteLine( Char::IsNumber( str, 3 ) ); // Output: "False"
}
using System;
public class IsNumberSample {
public static void Main() {
string str = "non-numeric";
Console.WriteLine(Char.IsNumber('8')); // Output: "True"
Console.WriteLine(Char.IsNumber(str, 3)); // Output: "False"
}
}
Module IsNumberSample
Sub Main()
Dim str As String
str = "non-numeric"
Console.WriteLine(Char.IsNumber("8"c)) ' Output: "True"
Console.WriteLine(Char.IsNumber(str, 3)) ' Output: "False"
End Sub
End Module
Uwagi
Ta metoda określa, czy Char ma być dowolna numeryczna kategoria Unicode.This method determines whether a Char is of any numeric Unicode category. Oprócz dołączania cyfr, cyfry zawierają znaki, ułamki, indeksy dolne, nadindeksy, cyfry rzymskie, liczniki walutowe i liczby obstawne.In addition to including digits, numbers include characters, fractions, subscripts, superscripts, Roman numerals, currency numerators, and encircled numbers. Ta metoda różni się od IsDigit metody, która określa, czy Char jest to podstawy-10.This method contrasts with the IsDigit method, which determines whether a Char is a radix-10 digit.
Pozycje znaku w ciągu są indeksowane począwszy od zera.Character positions in a string are indexed starting from zero.
Ważne
IsNumber(String, Int32)Metoda nie jest przeznaczona do określenia, czy ciąg składa się ze znaków numerycznych (na przykład przez wywołanie metody dla każdego znaku w ciągu).The IsNumber(String, Int32) method is not intended to determine whether a string consists of numeric characters (for example, by calling the method for each character in a string). Aby określić, czy ciąg składa się ze znaków numerycznych, wywołaj jedno z przeciążeń TryParse
metody (na przykład Int32.TryParse Double.TryParse typ całkowity lub zmiennoprzecinkowy).To determine whether a string consists of numeric characters, call one of the overloads of the TryParse
method (such as Int32.TryParse or Double.TryParse of an integral or floating point type.
Prawidłowe liczby to elementy należące do UnicodeCategory.DecimalDigitNumber UnicodeCategory.LetterNumber kategorii, lub UnicodeCategory.OtherNumber .Valid numbers are members of the UnicodeCategory.DecimalDigitNumber, UnicodeCategory.LetterNumber, or UnicodeCategory.OtherNumber category.
Jeśli Char obiekt w położeniu index
jest pierwszym znakiem prawidłowej pary dwuskładnikowej, IsNumber(String, Int32) Metoda określa, czy para zastępcza tworzy cyfrę liczbową.If the Char object at position index
is the first character of a valid surrogate pair, the IsNumber(String, Int32) method determines whether the surrogate pair forms a numeric digit. Na przykład system numeracji Morza Egejskiego składa się z kodów znaku U+10107 do U+10133.For example, the Aegean numbering system consists of code points U+10107 through U+10133. W poniższym przykładzie zastosowano ConvertFromUtf32 metodę w celu utworzenia wystąpienia ciągu reprezentującego numer Morza Egejskiego.The following example uses the ConvertFromUtf32 method to instantiate a string that represents AEGEAN NUMBER ONE. Jako dane wyjściowe z przykładu są wyświetlane, IsNumber(String, Int32) Metoda zwraca, true
Jeśli jest przekazywane górny SUROGAT numeru 1.As the output from the example shows, the IsNumber(String, Int32) method returns true
if it is passed the high surrogate of AEGEAN NUMBER ONE. Jeśli jednak przeszedł niski Surogat, bierze pod uwagę tylko kategorię niskiego surogatu i zwraca wartość false
.However, if it is passed the low surrogate, it considers only the category of the low surrogate and returns false
.
int utf32 = 0x10107; // AEGEAN NUMBER ONE
string surrogate = Char.ConvertFromUtf32(utf32);
for (int ctr = 0; ctr < surrogate.Length; ctr++)
Console.WriteLine("U+{0:X4} at position {1}: {2}",
Convert.ToUInt16(surrogate[ctr]), ctr,
Char.IsNumber(surrogate, ctr));
// The example displays the following output:
// U+D800 at position 0: True
// U+DD07 at position 1: False
Dim utf32 As Integer = &h10107 ' AEGEAN NUMBER ONE
Dim surrogate As String = Char.ConvertFromUtf32(utf32)
For ctr As Integer = 0 To surrogate.Length - 1
Console.WriteLine("U+{0:X4} at position {1}: {2}",
Convert.ToUInt16(surrogate(ctr)), ctr,
Char.IsNumber(surrogate, ctr))
Next
' The example displays the following output:
' U+D800 at position 0: True
' U+DD07 at position 1: False