1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

文字列操作[Visual Studio C#]

Last updated at Posted at 2020-05-02
//カッコで囲まれた文字を抽出する
string target = "4984988946484986486 (452E3D09047C8276)";
string pattern = @"(\()(?<body>.+?)(\))";
string body = Regex.Match(target, pattern).Groups["body"].Value;
//結果:body="452E3D09047C8276"

//IPアドレスが該当しているか(122.10.*.*)[正規表現]
string target2 = "122.10.1.1";
string pattern2 = @"122\.10\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])";
bool result = false;
//結果:result=true;

//カンマ区切り文字列を配列にする
string stCsvData = "csv1,csv2,csv3";
string[] stArrayCsvData = stCsvData.Split(',');

//タブ区切り文字列を配列にする
string stTsvData = "tsv1	tsv2	tsv3";
string[] stArrayTsvData = stTsvData.Split('\t');

//期間の開始日と終了日を分けて表示する
string kikan = "2018/08/08 - 2020/07/09";
string[] kikanArrayData = kikan.Split('-');
Array.ForEach<string>(kikanArrayData, x => kikanArrayData[Array.IndexOf<string>(kikanArrayData, x)] = x.Trim());

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?