문제

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.

도움이 되었습니까?

해결책

다른 팁

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top