/* Takes as input the standard format (As, Kh, ...) */ public static Card CreateFromString(String card) { Trace.Assert(card.Length == 2, "Cannot create a card from a string of length != 2"); String faceStr = new String(card[0], 1).ToUpper(); String suitStr = new String(card[1], 1).ToUpper(); CardFace face = Card.CharToCardFace(faceStr[0]); CardSuit suit = Card.CharToCardSuit(suitStr[0]); return(new Card(face, suit)); }
/* Given a string representing a card, returns the equivalent card object * This seems to be a standard format across poker client. * Cards are represented by two chars, the first indicating the face * and the second indicating the suit. Ex. Ks, Ah, etc. */ public virtual Card GenerateCardFromString(String card) { // This should never be different than 2 Trace.Assert(card.Length == 2, "A string representation of a card was found to be of invalid length: " + card.Length + " instead of 2"); // Uppercase to simplify checks String cardValues = card.ToUpper(); // Extract components Char faceComponent = cardValues[0]; Char suitComponent = cardValues[1]; CardFace face = Card.CharToCardFace(faceComponent); CardSuit suit = Card.CharToCardSuit(suitComponent); Card result = new Card(face, suit); return(result); }