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
  • 168,117
  • 40
  • 217
  • 433
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
  • 3,049
  • 1
  • 16
  • 18
Deepak
  • 2,287
  • 1
  • 23
  • 30
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,357
  • 5
  • 40
  • 55
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,952
  • 33
  • 46
0
url.toLowerCase().contains("dynamic code");
system.out.println(url+" from "+ dynamic code;
lawonga
  • 832
  • 10
  • 20