このインスタンスの文字を Unicode 文字配列へコピーします。
オーバーロードの一覧
このインスタンスの文字を Unicode 文字配列へコピーします。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Function ToCharArray() As Char()
[JScript] public function ToCharArray() : Char[];
このインスタンスの指定した部分文字列の文字を Unicode 文字配列へコピーします。
[Visual Basic] Overloads Public Function ToCharArray(Integer, Integer) As Char()
使用例
[Visual Basic, C#, C++] メモ ここでは、ToCharArray のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
' Sample for String.ToCharArray(Int32, Int32)
Imports System
Class Sample
Public Shared Sub Main()
Dim str As String = "012wxyz789"
Dim arr() As Char
arr = str.ToCharArray(3, 4)
Console.Write("The letters in '{0}' are: '", str)
Console.Write(arr)
Console.WriteLine("'")
Console.WriteLine("Each letter in '{0}' is:", str)
Dim c As Char
For Each c In arr
Console.WriteLine(c)
Next c
End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'The letters in '012wxyz789' are: 'wxyz'
'Each letter in '012wxyz789' is:
'w
'x
'y
'z
'
[C#]
// Sample for String.ToCharArray(Int32, Int32)
using System;
class Sample {
public static void Main() {
string str = "012wxyz789";
char[] arr;
arr = str.ToCharArray(3, 4);
Console.Write("The letters in '{0}' are: '", str);
Console.Write(arr);
Console.WriteLine("'");
Console.WriteLine("Each letter in '{0}' is:", str);
foreach (char c in arr)
Console.WriteLine(c);
}
}
/*
This example produces the following results:
The letters in '012wxyz789' are: 'wxyz'
Each letter in '012wxyz789' is:
w
x
y
z
*/
[C++]
// Sample for String::ToCharArray(Int32, Int32)
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;
int main()
{
String* str = S"012wxyz789";
Char arr[];
arr = str->ToCharArray(3, 4);
Console::Write(S"The letters in '{0}' are: '", str);
Console::Write(arr);
Console::WriteLine(S"'");
Console::WriteLine(S"Each letter in '{0}' is:", str);
IEnumerator* myEnum = arr->GetEnumerator();
while (myEnum->MoveNext()) {
Char c = *__try_cast<Char*>(myEnum->Current);
Console::WriteLine(c);
}
}
/*
This example produces the following results:
The letters in '012wxyz789' are: 'wxyz'
Each letter in '012wxyz789' is:
w
x
y
z
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。