Question

I have a string called "URL" which stores the url which comes dynamically. Now I would like to show whether the url from youtube or vimeo or facebook or google.

String URL = "https://www.youtube.com/watch?v=M0jmSsQ5ptw"; // this comes dynamically in my code

if [URL contains youtube word ] [ print "URL from YOUTUBE" ]

if [URL contains facebook word ] [ print "URL from FACEBOOK" ]

if [URL contains google word ] [ print "URL from GOOGLE" ]

if [URL contains vimeo word ] [ print "URL from VIMEo" ]

please help me how to find a word in a url.

Was it helpful?

Solution

OTHER TIPS

Try split()

    String URL = "https://www.youtube.com/watch?v=M0jmSsQ5ptw";
    System.out.println("URL from "+URL.split("\\.")[1].toUpperCase());

Output:

URL from YOUTUBE

you already answered your own question.

if [URL contains google word ] [ print "URL from GOOGLE" ]

if(URL.contains("google"))
print("URL from GOOGLE")
url.toLowerCase().contains("dynamic code");
system.out.println(url+" from "+ dynamic code;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top