このインスタンスの文字を Unicode 文字配列へコピーします。
Overloads Public Function ToCharArray() As Char()
[C#]
public char[] ToCharArray();
[C++]
public: __wchar_t ToCharArray() __gc[];
[JScript]
public function ToCharArray() : Char[];
戻り値
このインスタンスの各文字を要素とする Unicode 文字配列。このインスタンスが空の文字列である場合、返される配列は空で、長さは 0 になります。
使用例
[Visual Basic, C#, C++] String から Unicode 文字の配列を簡単に作成する方法を次の例に示します。この配列は、次に Split メソッドで使用されます。
Imports System
Imports Microsoft.VisualBasic
_
Public Class StringSplit2
Public Shared Sub Main()
Dim delimStr As String = " ,.:"
Dim delimiter As Char() = delimStr.ToCharArray()
Dim words As String = "one two,three:four."
Dim split As String() = Nothing
Console.WriteLine("The delimiters are -{0}-", delimStr)
Dim x As Integer
For x = 1 To 5
split = words.Split(delimiter, x)
Console.WriteLine(ControlChars.Cr + "count = {0,2} ..............", x)
Dim s As String
For Each s In split
Console.WriteLine("-{0}-", s)
Next s
Next x
End Sub 'Main
End Class 'StringSplit2
[C#]
using System;
public class StringSplit2 {
public static void Main() {
string delimStr = " ,.:";
char [] delimiter = delimStr.ToCharArray();
string words = "one two,three:four.";
string [] split = null;
Console.WriteLine("The delimiters are -{0}-", delimStr);
for (int x = 1; x <= 5; x++) {
split = words.Split(delimiter, x);
Console.WriteLine("\ncount = {0,2} ..............", x);
foreach (string s in split) {
Console.WriteLine("-{0}-", s);
}
}
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;
int main()
{
String* delimStr = S" ,.:";
Char delimiter[] = delimStr->ToCharArray();
String* words = S"one two,three:four.";
String* split[] = 0;
Console::WriteLine(S"The delimiters are -{0}-", delimStr);
for (int x = 1; x <= 5; x++) {
split = words->Split(delimiter, x);
Console::WriteLine(S"\ncount = {0, 2} ..............", __box(x));
IEnumerator* myEnum = split->GetEnumerator();
while (myEnum->MoveNext()) {
String* s = __try_cast<String*>(myEnum->Current);
Console::WriteLine(S"-{0}-", s);
}
}
}
[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
参照
String クラス | String メンバ | System 名前空間 | String.ToCharArray オーバーロードの一覧 | Char | Array