SQlite数据库包含“作为单词的一部分,无法将其作为字符串进行检索

时间:2017-05-27 11:07:59

标签: android database sqlite android-sqlite

我有“在角色中的单词数据库。 我使用Hotal.ttf字体,因为我的语言还没有unicode支持。

数据库中的单词是:K“ME @,如下所示:Oo ji matra

我正在从Android SQlite数据库中删除它并在文本视图中显示它。 这是查询代码:

//Get Meaning
public ArrayList<String> getMeaning(String search) {
    ArrayList<String> meaningList = new ArrayList<String>();
    String searchQuery = "SELECT kMean FROM dictionary WHERE eName LIKE '%" + search + "%' LIMIT 1";

    try {
        Cursor kCursor = this.getDbConnection().rawQuery(searchQuery, null);
        if (kCursor != null) {
            kCursor.moveToFirst();
            for (int i = 0; i < kCursor.getCount(); i++) {
                String sword = kCursor.getString(kCursor.getColumnIndexOrThrow("kMean"));
                meaningList.add(sword);
                kCursor.moveToNext();
            }
            kCursor.close();
            return meaningList;
        }
        return meaningList;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return meaningList;
}

然而,它被重新审核:enter image description here

所以我认为需要'而不是',并且enter image description here

显示enter image description here字母{}

请帮助。

enter image description here

1 个答案:

答案 0 :(得分:1)

希望它可以帮助您解决问题

  

它将用于对字符串进行编码/解码以防止连接   破裂

class Character{
    sf::Sprite mySprite;

    public:
    Character(){
        sf::texture aTex;
        aTex.loadFromFile("c:\users\noob\Desktop\myawesomegame\stripper.png");

        mySprite.setTexture(aTex);
    }
}

// attempt 2
class Character{
    sf::Sprite mySprite;

    public:
    Character(){
        std::unique_ptr<sf::Texture> texture(new sf::Texture);
        texture->loadFromFile("c:\users\noob\Desktop\myawesomegame\stripper.png");

        mySprite.setTexture(*texture);
    }
}
  

在数据库中存储之前编码/解码字符串

private String GenericMethodToCheckString(String name){
        if(name.contains("\"")){
            name= name.replace("\"", "####");
        }
        else if(name.contains("\'")){
            name= name.replace("\'", "##");
        }
        else if(name.contains("##")){
            name= name.replace( "##", "\'");
        }
        else if(name.contains("####")){
            name= name.replace("####", "\"");
        }

        return name;
    }
  

在搜索或获取之前编码/解码字符串

    private void InsertInDB(String hotelName){
        hotelName = GenericMethodToCheckString(hotelName);
        // now put your code to insert your hotel name in sqlite db
    }
  

以这种方式设置 //Get Meaning public ArrayList<String> getMeaning(String search) { search = GenericMethodToCheckString(search); ArrayList<String> meaningList = new ArrayList<String>(); String searchQuery = "SELECT kMean FROM dictionary WHERE eName LIKE '%" + search + "%' LIMIT 1"; try { Cursor kCursor = this.getDbConnection().rawQuery(searchQuery, null); if (kCursor != null) { kCursor.moveToFirst(); for (int i = 0; i < kCursor.getCount(); i++) { String sword = kCursor.getString(kCursor.getColumnIndexOrThrow("kMean")); meaningList.add(sword); kCursor.moveToNext(); } kCursor.close(); return meaningList; } return meaningList; } catch (Exception e) { e.printStackTrace(); } return meaningList; }

TextView