Problem with special character apostrophes in java and mysql
i have two string :
name="riyana's dream";
shopname= "my flower shop name is riyana's dream and it is nice.";
now i want to check whether shopname contains the string name in it or not. i tried with shopname.contains(name) in java but it didn't work. ac开发者_如何学Ctually shopname is fetched from mysql database. is it any problem?
please give me some idea about how to test whether shopname contains name in it or not.
Have you tried this?
String name ="riyana's dream";
String shopName = "my flower shop name is riyana's dream and it is nice.";
if(shopName.contains(name)){
System.out.println("Yes");
}else{
System.out.println("No");
}
It prints "Yes".
Special characters are no problem in Java. The contains() function works, so the problem is somewhere else.
If you use the JDBC API you can be sure the data is fetched correctly from the database. Please post more of your code.
The simple way is with contains method, i tried with your example and did work here is the code:
String name="riyana's dream";
String shopname= "my flower shop name is riyana's dream and it is nice.";
if(shopname.contains(name))
System.out.println("shopname contains the string name");
else
System.out.println("shopname NOT contains the string name");
精彩评论