How can I make a command block say a player's name?

How do I make a Minecraft command block to say somebody's name? I tried doing this:

/say You did it @p! 

Which says in the chat "You did it @p!".

This occurs on both Pocket Edition and on PC. Here's a screenshot showing what happens:

Chat text with selector


The reason it doesn't work is that you put a character directly after the @p. So, while:

/say You did it @p!

wouldn't work,

/say You did it @p !

does. Inconvenient, as it does include the space in the message, so it would come out as:

[@] You did it [USERNAME] !

However, I don't know a way around it.


You should use /tellraw. /say is not good for anything. example: /tellraw @a {"text":"Congrats you did it","color":"blue","extra":[{"selector":"@p"}]}