C#检查字长

Leg*_*989 -4 c#

如何检查字符串中每个单词的长度,如果一个大于10,则显示不同的响应?

半Psuedo

string allwords= "This is a test this is a test aaaaaaaaaaa this is a test";

if (allwords.Length < 10) {
      Console.WriteLine (allwords.Length);

}
else
{
   Console.WriteLine ("Woahh there one of these words is more than 10 chars");
}
Run Code Online (Sandbox Code Playgroud)

Oli*_*ver 7

你可以这样做:

allWords.Split(' ').Any(w => w.Length > 10);
Run Code Online (Sandbox Code Playgroud)