String.Chars[Int32] プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
public:
property char default[int] { char get(int index); };
public char this[int index] { get; }
member this.Chars(int) : char
Default Public ReadOnly Property Chars(index As Integer) As Char
パラメーター
- index
- Int32
現在の文字列内の位置。
プロパティ値
index
位置にあるオブジェクト。
例外
index
がこのオブジェクトの長さ以上か、0 未満です。
例
次の例では、ルーチンでこのインデクサーを使用して文字列を検証する方法を示します。
Console::Write( "Type a string : " );
String^ myString = Console::ReadLine();
for ( int i = 0; i < myString->Length; i++ )
if ( Uri::IsHexDigit( myString[ i ] ) )
Console::WriteLine( "{0} is a hexadecimal digit.", myString[ i ] );
else
Console::WriteLine( "{0} is not a hexadecimal digit.", myString[ i ] );
// The example produces output like the following:
// Type a string : 3f5EaZ
// 3 is a hexadecimal digit.
// f is a hexadecimal digit.
// 5 is a hexadecimal digit.
// E is a hexadecimal digit.
// a is a hexadecimal digit.
// Z is not a hexadecimal digit.
Console.Write("Type a string : ");
string myString = Console.ReadLine();
for (int i = 0; i < myString.Length; i ++)
if(Uri.IsHexDigit(myString[i]))
Console.WriteLine("{0} is a hexadecimal digit.", myString[i]);
else
Console.WriteLine("{0} is not a hexadecimal digit.", myString[i]);
// The example produces output like the following:
// Type a string : 3f5EaZ
// 3 is a hexadecimal digit.
// f is a hexadecimal digit.
// 5 is a hexadecimal digit.
// E is a hexadecimal digit.
// a is a hexadecimal digit.
// Z is not a hexadecimal digit.
Console.Write("Type a string : ")
Dim myString As String = Console.ReadLine()
Dim i As Integer
For i = 0 To myString.Length - 1
If Uri.IsHexDigit(myString.Chars(i)) Then
Console.WriteLine("{0} is a hexadecimal digit.", myString.Chars(i))
Else
Console.WriteLine("{0} is not a hexadecimal digit.", myString.Chars(i))
End If
Next
' The example produces output like the following:
' Type a string : 3f5EaZ
' 3 is a hexadecimal digit.
' f is a hexadecimal digit.
' 5 is a hexadecimal digit.
' E is a hexadecimal digit.
' a is a hexadecimal digit.
' Z is not a hexadecimal digit.
注釈
index
パラメーターは0から始まります。
このプロパティは、 Char パラメーターによって指定された位置にあるオブジェクトを返し index
ます。 ただし、Unicode 文字は複数の文字で表される場合があり Char ます。 オブジェクトでは System.Globalization.StringInfo なく Unicode 文字を操作するには、クラスを使用し Char ます。 詳細については、「クラスの概要」の「Char オブジェクトと Unicode 文字」セクションを参照してください String 。
C# では、 Chars[] プロパティはインデクサーです。 Visual Basic では、これはクラスの既定のプロパティです String 。 文字列内の各オブジェクトには Char 、次のようなコードを使用してアクセスできます。
string str1 = "Test";
for (int ctr = 0; ctr <= str1.Length - 1; ctr++ )
Console.Write("{0} ", str1[ctr]);
// The example displays the following output:
// T e s t
Dim str1 As String = "Test"
For ctr As Integer = 0 to str1.Length - 1
Console.Write("{0} ", str1(ctr))
Next
' The example displays the following output:
' T e s t