【发布时间】:2011-12-05 17:05:16
【问题描述】:
我正在为我的程序登录。我试图阻止用户输入一串重复字符,例如:111111 或 aaaaaa。
我该怎么做?
【问题讨论】:
标签: c# .net validation
我正在为我的程序登录。我试图阻止用户输入一串重复字符,例如:111111 或 aaaaaa。
我该怎么做?
【问题讨论】:
标签: c# .net validation
string str = ...
bool isValid = str.Distinct().Count() > 1;
【讨论】:
System.Linq 命名空间。
System.Linq 命名空间。
string input = ...
bool notAllSame = input.Distinct().Skip(1).Any();
【讨论】:
此功能会告诉您是否有重复。它根据原始长度检查不同字符的数量。如果它们不同,则说明您有重复...
bool containsDups = "ABCDEA".Length != s.Distinct().Count();
问候, 斯蒂芬
编辑
在这里找到你的答案: Testing for repeated characters in a string
【讨论】: