title: Using String in Switch Statement
body: <p>I am attempting to create a switch statement based upon a two character string. However, this doesn't seem to work and always evaluates to the default. So, could someone please show me the correct way to do it?</p>
  
  <p>Here is my (presumably incorrect) code:</p>
  
  <pre><code>string GetPieceCode(GameObject piece)
  {
      string pieceCode = "";
      Debug.Log(piece.gameObject);
      pieceCode = piece.ToString().Remove(2,2);
      Debug.Log(pieceCode);
      return pieceCode;
  }    
  
  Debug.Log(pieceType);
  switch (pieceType)
  {
      case "BP":
          Debug.Log("Black Pawn Selected");
          break;
      case "WP":
          Debug.Log("White Pawn Selected");
          break;
      case "WB":
          print("White Bishop Selected");
          break;
      case "BB":
          print("Black Bishop Selected");
          break;
      case "WK":
          print("White Knight Selected");
          break;
      case "BK":
          print("Black Knight Selected");
          break;
      case "WR":
          print("White Roook Selected");
          break;
      case "BR":
          print("Black Rook Selected");
          break;
      case "WKing":
          print("White King Selected");
          break;
      case "WQueen":
          print("White Queen Selected");
          break;
      case "BKing":
          print("Black King Selected");
          break;
      case "BQueen":
          print("Black Queen Selected");
          break;
      default;
          debug.log("Error");
          break;
  }
  </code></pre>
  
  <p>The initial <code>Debug.Log(pieceType)</code> prints out a 2 character string code which shows that it matches the case values. So I don't see what is going wrong.</p>
  
  <p>Also, <code>print()</code> and <code>Debug.Log()</code> are identical in this context.</p>