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

■文字列から部分文字列を抜き出す

Substring()関数を使います。
文字列の任意の位置から、任意のサイズだけ抜き出します。

C#
string str = "---Hello---";

// Helloを抜き出す
MessageBox.Show( str.Substring(3, 5) );

// 応用:文字列Helloを検索し、それを抜き出す
MessageBox.Show( str.Substring(str.IndexOf("Hello"), "Hello".Length) );
VB.NET
Dim str As String = "---Hello---"

'Helloを抜き出す
MessageBox.Show(str.Substring(3, 5))

'応用:文字列Helloを検索し、それを抜き出す
MessageBox.Show(str.Substring(str.IndexOf("Hello"), "Hello".Length))
VC.NET
String *str = "---Hello---";

// Helloを抜き出す
MessageBox::Show( str->Substring(3, 5) );

// 応用:文字列Helloを検索し、それを抜き出す
String *hello = "Hello";
MessageBox::Show( str->Substring(str->IndexOf("Hello"), hello->Length) );

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

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