Start by setting up an output line to copy into.
Then process the input line:
1) Create a variable called foundAt, set it to false.
2) Loop through input
2.1) If foundAt is true, check if this is a '{'.
2.1.1) If it is, loop though the input to find the matching '}'. This give you the name, so you can search the db, and copy the replacement string to the output. Set foundAt to false and use <code>continue</code> to skip the rest of your loop body.
2.1.2) If it isn't, copy an '@' to the output and clear foundAt
2.2 Is the input character an '@'?
2.2.1) If it is, set foundAt to true;
2.2.2) Otherwise, copy the character from the input to the output
3) Move on to the next input character and loop round again until all inputs are processed.
Make sense?