0

I have a couple of URLs:

a. https://iamterribleatthis/a

b. https://iamterribleatthis/a/index.html

I'm using Apache stringutls to see if 'a' is present in 'b' but I think that the forward slash is failing the comparison. Is there an easier/better way to find if 'a' is present in 'b' including the forward slash? Thanks.

user6123723
  • 10,546
  • 18
  • 67
  • 109
  • 4
    Showing your code might be helpful. Ideally forward slash shouldn't create any issue here. But why do you need `Apache StringUtils` class, rather than just using `String#contains()` method? – Rohit Jain Feb 24 '15 at 19:11
  • Do you want to find, if 'b' includes 'a' ? or longest matching substring ? – erencan Feb 24 '15 at 19:14
  • 1
    @RohitJain Thank you. It appeared like '/' was causing a problem but when I checked my code I found out a typo that was causing the problem. – user6123723 Feb 24 '15 at 19:17

2 Answers2

1
    String a = "https://iamterribleatthis/a";
    String b = "https://iamterribleatthis/a/index.html";

    System.out.println(b.contains(a));
Noomak
  • 371
  • 5
  • 19
1

Convert the URL to his external form and use indexOf():

b.toExternalForm().indexOf(a.toExternalForm())

if the return value is bigger than -1 a is a part of b

Jens
  • 67,715
  • 15
  • 98
  • 113