「C#」Replaceメソッドで文字列中の文字を置換する
書式
対象文字列.Replace(“置換対象文字”, “置換後文字”);
使用例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string target = "study skill";
Console.WriteLine("置換前: "+target);
String result = target.Replace("study", "arkgame");
Console.WriteLine("置換後: "+result);
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string target = "study skill";
Console.WriteLine("置換前: "+target);
String result = target.Replace("study", "arkgame");
Console.WriteLine("置換後: "+result);
Console.ReadKey();
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string target = "study skill"; Console.WriteLine("置換前: "+target); String result = target.Replace("study", "arkgame"); Console.WriteLine("置換後: "+result); Console.ReadKey(); } } }
結果
置換前: study skill
置換後: arkgame skill