Skip to content

Instantly share code, notes, and snippets.

@Danielkaas94
Last active January 29, 2018 18:23
Show Gist options
  • Save Danielkaas94/d1f77d05caf305fe0f06ccc80faed03e to your computer and use it in GitHub Desktop.
Save Danielkaas94/d1f77d05caf305fe0f06ccc80faed03e to your computer and use it in GitHub Desktop.
CountSmileys in my way and as RegularExpression
private static int CountSmiley(string[] smileys)
{
// :) :D ;-D :~) - Valid.
// ;( :> :} :] - Invalid.
int counter = 0;
foreach (string item in smileys)
{
switch (item)
{
case ":D":
counter++;
break;
case ":~)":
counter++;
break;
case ";~D":
counter++;
break;
case ":-)":
break;
case ":)":
counter++;
break;
case ";-D":
counter++;
break;
case ";D":
counter++;
break;
case ";-)":
counter++;
break;
case ":-D":
counter++;
break;
case ";)":
counter++;
break;
case ";~)":
counter++;
break;
case ":~D":
counter++;
break;
}
}
return counter;
}
public static int CountSmileys2(string[] smileys)
{
return smileys.Count(s => Regex.IsMatch(s, @"^[:;]{1}[~-]{0,1}[\)D]{1}$"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment