String.ToCharArray メソッド ()
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim returnValue As Char() returnValue = instance.ToCharArray
このインスタンスの各文字を要素とする Unicode 文字配列。このインスタンスが空の文字列である場合、返される配列は空で、長さは 0 になります。

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
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); } } } }
using namespace System; using namespace System::Collections; int main() { String^ delimStr = " ,.:"; array<Char>^delimiter = delimStr->ToCharArray(); String^ words = "one two,three:four."; array<String^>^split = nullptr; 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 ); IEnumerator^ myEnum = split->GetEnumerator(); while ( myEnum->MoveNext() ) { String^ s = safe_cast<String^>(myEnum->Current); Console::WriteLine( "-{0}-", s ); } } }
import System.*; public class StringSplit2 { public static void main(String[] args) { 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} ..............", System.Convert.ToString(x)); for (int iCtr = 0; iCtr < split.get_Length(); iCtr++) { String s = split[iCtr]; Console.WriteLine("-{0}-", s); } } } //main } //StringSplit2

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.ToCharArray メソッド (Int32, Int32)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim startIndex As Integer Dim length As Integer Dim returnValue As Char() returnValue = instance.ToCharArray(startIndex, length)
戻り値
このインスタンスの文字位置 startIndex から、length の数の文字を要素とする Unicode 文字配列。


length が 0 の場合、startIndex の値は無視され、文字列全体がこのインスタンスの先頭からコピーされます。このインスタンスが空の文字列 ("") である場合、返される配列は空で、長さは 0 になります。

文字列から部分文字列を取り出して文字の配列に変換し、配列の要素を列挙しながら表示するコード例を次に示します。
' 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 '
// 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 */
// Sample for String::ToCharArray(Int32, Int32) using namespace System; using namespace System::Collections; int main() { String^ str = "012wxyz789"; array<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 ); IEnumerator^ myEnum = arr->GetEnumerator(); while ( myEnum->MoveNext() ) { Char c = safe_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 */
// Sample for String.ToCharArray(Int32, Int32) import System.*; class Sample { public static void main(String[] args) { 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); for (int iCtr = 0; iCtr < arr.length; iCtr++) { char c = arr[iCtr]; Console.WriteLine(c); } } //main } //Sample /* This example produces the following results: The letters in '012wxyz789' are: 'wxyz' Each letter in '012wxyz789' is: w x y z */

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.ToCharArray メソッド
Weblioに収録されているすべての辞書からString.ToCharArrayを検索する場合は、下記のリンクをクリックしてください。

- String.ToCharArrayのページへのリンク