文字列から特定の部分だけを削除するサンプル

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

image

戻る