import java.net.MalformedURLException; import java.net.URL; // // The following example code demonstrates how to // get the domain name from a URL String // public class GetDomainNameFromURL { public static void main(String[] args) throws MalformedURLException { String testURLString = "https://thermodynamiccomputing.com/main?&t=20&f=52"; URL lURL = new URL(testURLString); String hostName = lURL.getHost(); System.out.println(hostName); testURLString = "http://www.thermodynamiccomputing.com/main?&t=20&f=52"; lURL = new URL(testURLString); hostName = lURL.getHost(); System.out.println(hostName); testURLString = "http://www.sub.thermodynamiccomputing.com/main?&t=20&f=52"; lURL = new URL(testURLString); hostName = lURL.getHost(); System.out.println(hostName); } }
Here is the output of the example code:
thermodynamiccomputing.com www.thermodynamiccomputing.com www.sub.thermodynamiccomputing.comPiece of cake!!!
No comments:
Post a Comment