.NET C#,VB.NET,VC.NET

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

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

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

C#
string str = "ho";

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

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

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

'応用:oを検索し、その位置へ挿入
MessageBox.Show(str.Insert(str.IndexOf("o"), "ell"))
VC.NET
String *str = "ho";

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

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

トップ  > .NET C#,VB.NET,VC.NET
Copyright (C) 2005.09 〜 By Shougo Suzaki

SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送