String.ToCharArray メソッド ()とは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > String.ToCharArray メソッド ()の意味・解説 

String.ToCharArray メソッド ()

このインスタンス文字Unicode 文字配列コピーします

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

public char[] ToCharArray ()
public:
array<wchar_t>^ ToCharArray ()
public char[] ToCharArray ()
public function ToCharArray () : char[]

戻り値
このインスタンスの各文字要素とする 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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

String.ToCharArray メソッド (Int32, Int32)

このインスタンス指定した部分文字列文字Unicode 文字配列コピーします

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function ToCharArray ( _
    startIndex As Integer, _
    length As Integer _
) As Char()
Dim instance As String
Dim startIndex As Integer
Dim length As Integer
Dim returnValue As Char()

returnValue = instance.ToCharArray(startIndex, length)
public char[] ToCharArray (
    int startIndex,
    int length
)
public:
array<wchar_t>^ ToCharArray (
    int startIndex, 
    int length
)
public char[] ToCharArray (
    int startIndex, 
    int length
)
public function ToCharArray (
    startIndex : int, 
    length : int
) : char[]

パラメータ

startIndex

このインスタンス内の部分文字列開始位置

length

このインスタンス内の文字列長さ

戻り値
このインスタンス文字位置 startIndex から、length の数の文字要素とする Unicode 文字配列

例外例外
例外種類条件

ArgumentOutOfRangeException

startIndex または length が 0 未満です。

または

startIndexlength合計した値が、このインスタンス長さよりも大きい値です。

解説解説
使用例使用例

文字列から部分文字列取り出して文字配列変換し配列要素列挙しながら表示するコード例次に示します

' 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
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

String.ToCharArray メソッド



このページでは「.NET Framework クラス ライブラリ リファレンス」からString.ToCharArray メソッド ()を検索した結果を表示しています。
Weblioに収録されているすべての辞書からString.ToCharArray メソッド ()を検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からString.ToCharArray メソッド ()を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

String.ToCharArray メソッド ()のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



String.ToCharArray メソッド ()のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS