文字列を特定文字を基点に分割するサンプル

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             // 文字列の分割
  13.             String[] strList = "リンゴ,バナナ,イチゴ".Split(',');
  14.             Console.WriteLine("\"リンゴ,バナナ,イチゴ\".Split(',')");
  15.             Console.WriteLine("\n【結果】");
  16.             foreach (String str in strList)
  17.             {
  18.                 Console.WriteLine(str);
  19.             }
  20.             Console.ReadLine();
  21.         }
  22.     }
  23. }

image

戻る