Quick code snippet today. Let’s say you have some URLs that you want to change the hostname/port on it without having to do string manipulation.
1 | //multiple constructor are available |
There you go! It’s as easy as this. This will avoid countless hour of parsing a URL for the hostname, port number or whatever else you are searching.
The bonus with that is that the path of the URL won’t be touched at all.
Have fun!