指定した文字列の指定位置にある文字が数字かどうかを示します。
Overloads Public Shared Function IsNumber( _
ByVal s As String, _ ByVal index As Integer _) As Boolean
[C#]
public static bool IsNumber(strings,intindex);
[C++]
public: static bool IsNumber(String* s,intindex);
[JScript]
public static function IsNumber(
s : String,index : int) : Boolean;
パラメータ
- s
文字列。 - index
s 内の文字位置。
戻り値
s の index の位置にある文字が数字である場合は true 。それ以外の場合は false 。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | s が null 参照 (Visual Basic では Nothing) です。 |
ArgumentOutOfRangeException | index が 0 未満か、 s の最後の位置より大きい値です。 |
解説
このメソッドは、 Char がいずれかの数値 Unicode カテゴリに属するかどうかを判断します。これは、 Char が基数 10 の数字かどうかを判断する IsDigit とは対照的なメソッドです。
文字列の文字位置には、0 から始まるインデックスが付けられます。
有効な数値は、 UnicodeCategory のカテゴリ DecimalDigitNumber 、 LetterNumber 、または OtherNumber のメンバです。
使用例
[Visual Basic, C#, C++] IsNumber のサンプルを次に示します。
Imports System
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
[C#]
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"
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
int main() {
String* str = "non-numeric";
Console::WriteLine(Char::IsNumber('8')); // Output: "True"
Console::WriteLine(Char::IsNumber(str, 3)); // Output: "False"
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
Char 構造体 | Char メンバ | System 名前空間 | Char.IsNumber オーバーロードの一覧 | Boolean | String | IsDigit