C# 正则匹配键盘行(或列)连续字符 ,3连连续字符匹配
https://blog.csdn.net/qq_20173195/article/details/126989662 参考
using System; public class Program { public static void Main() { Console.WriteLine(CheckKeyboardContinuousChar(",./")); } public static bool CheckKeyboardContinuousChar(string str) { char[][] c1 = { new char[] { '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+' }, new char[] { 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '{', '}', '|' }, new char[] { 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '"' }, new char[] { 'z', 'x', 'c', 'v', 'b', 'n', 'm', '<', '>', '?' } }; char[][] c2 = { new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=' }, new char[] { 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\' }, new char[] { 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'' }, new char[] { 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/' } }; str = str.ToLower(); char[] strArray = str.ToCharArray(); int[] y = new int[strArray.Length]; int[] x = new int[strArray.Length]; for (int c = 0; c < strArray.Length; c++) { y[c] = 0; // 当做~`键处理 x[c] = -1; for (int i = 0; i < c1.Length; i++) { for (int j = 0; j < c1[i].Length; j++) { if (strArray[c] == c1[i][j]) { y[c] = i; x[c] = j; } } } if (x[c] != -1) { continue; } for (int i = 0; i < c2.Length; i++) { for (int j = 0; j < c2[i].Length; j++) { if (strArray[c] == c2[i][j]) { y[c] = i; x[c] = j; } } } } for (int c = 1; c < strArray.Length - 1; c++) { if (y[c - 1] == y[c] && y[c] == y[c + 1]) // 横着同一行 { if ((x[c - 1] + 1 == x[c] && x[c] + 1 == x[c + 1]) || (x[c + 1] + 1 == x[c] && x[c] + 1 == x[c - 1])) { return true; } } if (x[c - 1] == x[c] && x[c] == x[c + 1]) // 竖着同一列 { if ((y[c - 1] + 1 == y[c] && y[c] + 1 == y[c + 1]) || (y[c + 1] + 1 == y[c] && y[c] + 1 == y[c - 1])) { return true; } } if ((x[c - 1] + 1 == x[c] && x[c] + 1 == x[c + 1]) || (x[c - 1] - 1 == x[c] && x[c] - 1 == x[c + 1])) { if ((y[c - 1] + 1 == y[c] && y[c] + 1 == y[c + 1]) || (y[c + 1] + 1 == y[c] && y[c] + 1 == y[c - 1])) { return true; } } } return false; } }
分类:
C#
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2021-05-21 layui的layer.open弹出层高度自适应的解决
2018-05-21 SQL 检查 Varchar 是否能转换为 NUMERIC