Last active
January 29, 2018 18:23
-
-
Save Danielkaas94/d1f77d05caf305fe0f06ccc80faed03e to your computer and use it in GitHub Desktop.
CountSmileys in my way and as RegularExpression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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