Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java在字符串URL中搜索子字符串URL_Java_String_Comparison_String Comparison_Apache Stringutils - Fatal编程技术网

Java在字符串URL中搜索子字符串URL

Java在字符串URL中搜索子字符串URL,java,string,comparison,string-comparison,apache-stringutils,Java,String,Comparison,String Comparison,Apache Stringutils,我有几个URL: a. https://iamterribleatthis/a b. https://iamterribleatthis/a/index.html 我使用ApacheStringUTLS来查看“b”中是否存在“a”,但我认为正斜杠无法进行比较。是否有更简单/更好的方法来确定“b”中是否存在“a”,包括正斜杠?谢谢。将URL转换为他的外部形式并使用indexOf(): String a = "https://iamterribleatthis/a"; Strin

我有几个URL:

a. https://iamterribleatthis/a

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

我使用ApacheStringUTLS来查看“b”中是否存在“a”,但我认为正斜杠无法进行比较。是否有更简单/更好的方法来确定“b”中是否存在“a”,包括正斜杠?谢谢。

将URL转换为他的外部形式并使用
indexOf()

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

    System.out.println(b.contains(a));

如果返回值大于-1,则a是b的一部分,显示代码可能会有所帮助。理想情况下,正斜杠不会在这里产生任何问题。但是为什么您需要
apachestringutils
类,而不仅仅是使用
String#contains()
方法呢?如果“b”包括“a”,您想查找吗?还是最长的匹配子串?@RohitJain谢谢。看起来好像是“/”引起了问题,但当我检查代码时,我发现是打字错误导致了问题。
b.toExternalForm().indexOf(a.toExternalForm())