How do you respond to this?

What do you say when someone tells you they have been diagnosed with cancer? Or that they love have cancer? It’s something that I never really know how to respond . I always say I’m so sorry but I don’t know if that’s even appropriate or what else to say. Do you also ask what type of cancer or what stage if they don’t tell you ?