header
CodePanic! > C#.NET Tips > 今ここ

■文字列中に文字列を挿入

Insert()関数を使います。
挿入位置は数値で指定します。
最初の1文字目のインデックスは0からはじまります。

文字列hoの、hの後ろに
文字列ellを挿入して、helloを作るサンプルです。

string str = "ho";

// 文字列の挿入
MessageBox.Show( str.Insert(1, "ell") );

// 応用:oを検索し、その位置へ挿入
MessageBox.Show( str.Insert(str.IndexOf("o"), "ell") );





Copyright © 2008.07 - shougo suzaki