如何使用"喜欢"和"%QUOT;检查相似变量的Andr​​oid(Java的code) [英] How use "LIKE" and "%" to check similarity to variable in android(Java code)

查看:175
本文介绍了如何使用"喜欢"和"%QUOT;检查相似变量的Andr​​oid(Java的code)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Java的Andr​​oid应用程序的工作,我需要查询数据库中的Java code,以检查是否userinput(变量)语句包含文字使用的是在我的SQLite数据库 LIKE 查询和 rowQuery 方法的Java code,

我用这个code,但它没有工作:


 光标= db.rawQuery(选择shompet FROM句WHERE+列+LIKE'%
                              + NewMessage作为+%',NULL);


NewMessage作为是我的变量(userInput)

我看过类似的话题,但无论他们不是我的答案或者他们是如此的复杂。


解决方案

在除权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 });

这篇关于如何使用"喜欢"和"%QUOT;检查相似变量的Andr​​oid(Java的code)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆