「C#」で文字列を検索するには、
・IndexOf
・LastIndexOf
・StartsWith
・EndsWith
・System.Text.RegularExpressions.Regex.IsMatch
を使用する。
| メソッド | 説明 |
| IndexOf | |
| LastIndexOf | |
| StartsWith | |
| EndsWith | |
| | |
| System.Text.RegularExpressions.Regex.IsMatch | 正規表現で文字列を検索 |
文字列の検索
bool 変数名 = 変数名.StartsWith("検索文字列");
bool 変数名 = 変数名.StartsWith("検索文字列", System.StringComparison.CurrentCultureIgnoreCase);
bool 変数名 = 変数名.EndsWith("検索文字列", System.StringComparison.CurrentCultureIgnoreCase);
int 変数名 = 変数名.IndexOf("検索文字列") + "検索文字列".Length;
int 変数名 = 変数名.LastIndexOf("検索文字列");
string 変数名 = 変数名.Substring(first, last - first);
bool 変数名 =
System.Text.RegularExpressions.Regex.IsMatch(検索する文字列変数, "検索文字列", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Back