How you score a hand will depend on the rules of the game being played.
But here's a way to at least extract the parts of the data you want by using a Regular Expression.
I would likely parse the string values into enumerated values for easier comparisons.
Also, if you are in control of the format of the file, then I recommend putting the suit before the rank.
result += CP.Cards.ParseCards
(
@"
Player1:AH,3C,8C,2S,JD
Player2:KD,QH,10C,4C,AC
Player3:6S,8D,3D,JH,2D
Player4:5H,3S,KH,AS,9D
Player5:JS,3H,2H,2C,4D
"
) ;
namespace CP
{
public static partial class Cards
{
private static readonly System.Collections.Generic.Dictionary<string,string> deck ;
private static readonly System.Text.RegularExpressions.Regex reg ;
static Cards
(
)
{
deck = new System.Collections.Generic.Dictionary<string,string>
(
System.StringComparer.InvariantCultureIgnoreCase
)
{
{ "H" , "Hearts" } , { "C" , "Clubs" } , { "S" , "Spades" } , { "D" , "Diamonds" } ,
{ "A" , "Ace" } , { "2" , "Two" } , { "3" , "Three" } , { "4" , "Four" } ,
{ "5" , "Five" } , { "6" , "Six" } , { "7" , "Seven" } , { "8" , "Eight" } ,
{ "9" , "Nine" } , { "10" , "Ten" } , { "J" , "Jack" } , { "Q" , "Queen" } ,
{ "K" , "King" }
} ;
reg = new System.Text.RegularExpressions.Regex
(
@"((^|\G)\s*(?'Player'[^:]+):(?'Card'(?'Rank'\w{1,2})(?'Suit'[HCSD])\s*(,|$)){5})"
,
System.Text.RegularExpressions.RegexOptions.Compiled
|
System.Text.RegularExpressions.RegexOptions.IgnoreCase
|
System.Text.RegularExpressions.RegexOptions.Multiline
) ;
return ;
}
public static int
ParseCards
(
string Cards
)
{
System.Text.RegularExpressions.MatchCollection mat = reg.Matches ( Cards ) ;
for ( int i = 0 ; i < mat.Count ; i++ )
{
System.Console.Write ( "\r\n{0} means {1} has :" , mat [ i ].Value.Trim() , mat [ i ].Groups [ "Player" ].Value ) ;
System.Text.RegularExpressions.Group rank = mat [ i ].Groups [ "Rank" ] ;
System.Text.RegularExpressions.Group suit = mat [ i ].Groups [ "Suit" ] ;
for ( int j = 0 ; j < mat [ i ].Groups [ "Card" ].Captures.Count ; j++ )
{
System.Console.Write ( " {0} of {1}" , deck [ rank.Captures [ j ].Value ] , deck [ suit.Captures [ j ].Value ] ) ;
}
}
return ( mat.Count ) ;
}
}
}