Many, but by no means all, programs have the option to bind to a specific address. Some, like wget (as pointed out by fbh) have a command-line option to specify which address to bind to. Many more server-like programs, such as apache and squid, control this in their configuration file. It's always going to be program-specific.
For programs that don't support binding to a specific address, your options may be more limited, depending on what sort of program you're dealing with.
For a server program (that accepts incoming connections), you can usually accomplish the same thing by listening on all addresses (which is usually the default), then using iptables, or your external router, to forewall the other addresses.
The trickier thing is for outbound connections. Here you'll need something more like described in the answer you linked to in your question. The problem with that is its dependent on the destination address, not the source program.
You may be able to accomplish what you want with iptables and a SNAT rule.
iptables -A POSTROUTING -p tcp --dport 80 -j SNAT --to-source 18.104.22.168
This iptables rule (which I have not tested), ought to change the source address on any traffic going to port 80. If you need the same behavior for both tcp and udp traffic, you'd need to create two rules, replacing '-p tcp' with '-p udp' in the second one.