2011-12-05 6 views
0

私のプログラムのログインに取り組んでいます。私はユーザが111111またはaaaaaaのような繰り返し文字列を入力するのを防止しようとしています。文字列が同じ文字の繰り返しで構成されているかどうかをチェックする方法は?

どうすればよいですか?

+2

のhttp:彼らは異なっている場合は、重複...

bool containsDups = "ABCDEA".Length != s.Distinct().Count(); 

挨拶し、 ステファン

編集ここにあなたの答えを見つけることが

持っています:/stackoverflow.com/questions/829537/testing-for-repeated-characters-in-a-string –

答えて

2
string input = ... 
bool notAllSame = input.Distinct().Skip(1).Any(); 
9
string str = ... 
bool isValid = str.Distinct().Count() > 1; 
+0

このために名前空間を追加する必要がありますか? 'txtPassword.Text.Distinct()。Count()> 1'のようには機能しません。 – HelpNeeder

+3

'System.Linq'名前空間を追加してください。 – Amy

+0

はい、 'System.Linq'名前空間が必要です。 –

関連する問題