반응형

이 인스턴스의 문자를 유니코드 문자 배열에 복사합니다.

네임스페이스:  System
어셈블리:  mscorlib(mscorlib.dll)
C#
public char[] ToCharArray()

반환 값

형식: array<System..::.Char>[]()[]
해당 요소가 이 인스턴스의 각 문자로 이루어진 유니코드 문자 배열을 반환합니다. 이 인스턴스가 빈 문자열이면 반환된 배열은 길이가 0인 빈 배열입니다.

다음 코드 예제에서는 String에서 유니코드 문자 배열을 쉽게 만드는 방법을 보여 줍니다. 만들어진 배열은 Split 메서드에서 사용됩니다.

using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      string delimStr = " ,.:";
      char[] delimiter = delimStr.ToCharArray();
      string words = "one two,three:four.";
      string[] split = null;

      outputBlock.Text += "The delimiters are:" + "\n";
      foreach (char ch in delimStr)
         outputBlock.Text += String.Format("   '{0}'", ch) + "\n";

      outputBlock.Text += "\n";

      split = words.Split(delimiter);
      foreach (string s in split)
      {
         outputBlock.Text += String.Format("'{0}'", s) + "\n";
      }
   }
}
// The example displays the following output:
//       
//       The delimiters are:
//          ''
//          ','
//          '.'
//          ':'
//          
//       'one'
//       'two'
//       'three'
//       'four'
//       ''    
반응형

'프로젝트 > 메신저관련' 카테고리의 다른 글

DescriptionAttribute 클래스  (0) 2010.02.19
extern(C# 참조)  (0) 2010.02.19
Collection / ArrayList / HashTable  (0) 2010.02.19

+ Recent posts