且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用"喜欢"和"%QUOT;检查相似变量的Andr​​oid(Java的code)

更新时间:2022-12-08 21:35:31

在除权pression 'HI'LIKE'%你好%',它是无法找到的任何的字符替换通配符使字符串将匹配。

您需要做的比较其他方式,即'你好'LIKE'%你好%'

  db.rawQuery(选择shompet FROM句+
            在哪里?LIKE'%'||+列+||'%',
            新的String [] {NewMessage作为});

I am working on Android app using Java, I need to query database in Java code to check if userinput(variable) statement is contain words which are in my SQLite DataBase using LIKE in query and rowQuery method in java code,

I used this code but it did not work:

cursor = db.rawQuery("SELECT shompet FROM sentence WHERE " + column + " LIKE '%"
                              + newMessage + "%'", null);

newMessage is my variable(userInput)

I read similar topics but either they are not my answer or they are so complicated.

In the expression 'hi' LIKE '%hi there%', it is not possible to find any characters to replace the % wildcards so that the strings would match.

You need to do the comparison the other way around, i.e., 'hi there' LIKE '%hi%':

db.rawQuery("SELECT shompet FROM sentence" +
            " WHERE ? LIKE '%' || " + column + " || '%'",
            new String[] { newMessage });