Form1.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.Text;
  2. namespace RosterSnap
  3. {
  4. public partial class Form1 : Form
  5. {
  6. public Form1()
  7. {
  8. InitializeComponent();
  9. }
  10. private void textBox1_TextChanged(object sender, EventArgs e)
  11. {
  12. OnTextChanged();
  13. }
  14. private void textBox2_TextChanged(object sender, EventArgs e)
  15. {
  16. OnTextChanged();
  17. }
  18. private void OnTextChanged()
  19. {
  20. // 1. 左侧名单
  21. var roster = SplitLines(textBox1.Text);
  22. // 2. 右侧接龙:去掉行首序号、点号、空格等,只保留名字
  23. var dragonRaw = SplitLines(textBox2.Text);
  24. var dragon = new List<string>();
  25. foreach (var line in dragonRaw)
  26. {
  27. // 去掉行首的 #接龙、例 姓名 等无用行
  28. if (line.StartsWith("#") || line.StartsWith("例")) continue;
  29. // 用正则把 “数字. 姓名 备注” 中的姓名提取出来
  30. var match = System.Text.RegularExpressions.Regex.Match(line, @"^\s*\d+\.\s*([^\s]+)");
  31. if (match.Success)
  32. dragon.Add(match.Groups[1].Value);
  33. }
  34. // 3. 比对
  35. var missing = roster
  36. .Where(n => !dragon.Contains(n, StringComparer.OrdinalIgnoreCase))
  37. .ToList();
  38. var sb = new StringBuilder();
  39. sb.AppendLine($"名单共 {roster.Count} 人,接龙中已出现 {roster.Count - missing.Count} 人。");
  40. if (missing.Count == 0)
  41. {
  42. sb.AppendLine("✅ 所有人已接龙。");
  43. }
  44. else
  45. {
  46. sb.AppendLine($"❌ 以下 {missing.Count} 人缺席:");
  47. missing.ForEach(n => sb.AppendLine(n));
  48. }
  49. textBox3.Text = sb.ToString();
  50. }
  51. private static List<string> SplitLines(string text) =>
  52. text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)
  53. .Select(s => s.Trim())
  54. .Where(s => !string.IsNullOrWhiteSpace(s))
  55. .ToList();
  56. private void linkLabel1_Click(object sender, EventArgs e)
  57. {
  58. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
  59. {
  60. FileName = linkLabel1.Text,
  61. UseShellExecute = true
  62. });
  63. }
  64. }
  65. }