0

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.

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
RaghavaRaj
  • 23
  • 1
  • 2
  • 4

4 Answers4

1

use url.contains("whatyouwant")

ref : http://docs.oracle.com/javase/7/docs/api/java/lang/String.html

codelovesme
  • 2,632
  • 1
  • 14
  • 18
Deepak
  • 1,729
  • 17
  • 28
0

Try split()

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

Output:

URL from YOUTUBE
Rakesh KR
  • 6,207
  • 5
  • 41
  • 51
0

you already answered your own question.

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

if(URL.contains("google"))
print("URL from GOOGLE")
Foolish
  • 3,582
  • 28
  • 41
0
url.toLowerCase().contains("dynamic code");
system.out.println(url+" from "+ dynamic code;
lawonga
  • 782
  • 8
  • 18