文字列を置換するサンプル

  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("\"リンゴ,バナナ,イチゴ\".Replace(\"バナナ\", \"オレンジ\") → " + "リンゴ,バナナ,イチゴ".Replace("バナナ", "オレンジ")); // 「バナナ」を「オレンジ」に置換して返却
  14.             Console.ReadLine();
  15.         }
  16.     }
  17. }

image

戻る