A spectroscopic study of carbanions and corresponding nitranions: ion pair formation in the ground state and the first excited state