Can I OFFSET/avoid the NC (NC DOR) tax on capital gains, if I ALSO cash out stocks with an equal (negative) amount in losses, to the state? Is there a limit on losses?

My question is only about NC state (NCDOR) income taxes (not federal). I am considering cashing out some stocks. I know I would have to pay a flat 5.25% on any capital gains to the state, but can I OFFSET the amount (of capital gains), if I ALSO cash out stocks with an equal (but negative) amount in capital losses? Can I do this to avoid paying capital gains tax to the state? Also, is there a limit in NC on how much I can deduct in capital losses for the state of NC?