How do I compare the String
http://192.168.74.1/sp/info.php?prodnum=0000000001
with
http://192.168.74.1
I only need to get the http://192.168.74.1 part of first string.
You don't need to extract anything from the first string. You can use String.startsWith:
if (string1.startsWith(string2)) {
// do something
}
1) you can use beginwith function
String Mainstring= "http: // 192.168.74.1/sp/info.php?prodnum=0000000001";
if (Mainstring.startsWith("http: // 192.168.74.1"))
{
//Write your code here
}
2) you can use contains function
boolean retval = Mainstring.contains(cs1);
retval will be true if it exist otherwise false.
Although checking .startsWith(...) is sufficient, since you want to match urls, it is better to parse the url and break it into components. This can be done manually, using regular expressions, but it is probably safer to use the java url parser. See parsing a URL for details.