文字列から特定の部分だけを取り出すサンプル

  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.             Console.WriteLine("\"ABCDE\".Substring(2) → " + "ABCDE".Substring(2));          // 3文字目から後ろ全てを返却
  14.             Console.WriteLine("\"ABCDE\".Substring(1, 3) → " + "ABCDE".Substring(1, 3));  // 2文字から4文字目を返却
  15.             Console.ReadLine();
  16.         }
  17.     }
  18. }

image

戻る