Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing strings in java android

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.

like image 678
duderbear Avatar asked Jul 06 '26 21:07

duderbear


2 Answers

You don't need to extract anything from the first string. You can use String.startsWith:

if (string1.startsWith(string2)) {
  // do something
}
like image 180
devnull Avatar answered Jul 08 '26 11:07

devnull


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.

like image 28
kaushik parmar Avatar answered Jul 08 '26 10:07

kaushik parmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!