if (Clipboard.ContainsText())
{
string[] _kugiri = { "\r\n" };
List<string> lines = new List<string>();
lines = Clipboard.GetText().Split(_kugiri, StringSplitOptions.RemoveEmptyEntries).ToList();
lines.RemoveAll(s => !Regex.IsMatch(s, @"^\d+"));
if (lines.Count() != 0)
{
string result = String.Join("\r\n", lines.ToArray());
Clipboard.SetText(result);
}
}
- 数字から始まる行のみを抽出し、さらに先頭の数字を消去する
string textBox1_text = textBox1.Text;
string[] lines = textBox1_text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
Regex rgx = new Regex(@"^\d+\s+");
IEnumerable<string> result = lines
.Where(s => rgx.IsMatch(s))
.Select(s => rgx.Replace(s, ""));
string final_result = String.Join("\r\n", result.ToArray());
textBox2.Text = final_result;