Is there a way to search through a string and then convert them into something else?

For example:
Dallas, TX to TX
Fargo North Datkota to ND
D.C. to DC
Twin Cities, M-N to MN

I hope that clear.
Troy