【问题标题】:rms queries, find a phrase inside a textrms 查询,在文本中查找短语
【发布时间】:2011-11-26 18:49:08
【问题描述】:

我想做一个 midlet 应用程序来保存带有条形码、产品名称、产品描述和价格的产品。然后将它保存为它:

123123123-coca cola-soda-6.50 124512341-水晶coca-soda-7.00

为此我已经构建了这段代码:

public boolean  ProductoAgregar(String dato) // add product
{
    byte bytes[] = dato.getBytes();
        try {
            rs.addRecord(bytes, 0, bytes.length);
       return true;
        } catch (RecordStoreException ex) {
            ex.printStackTrace();
       return false;
        }


}

public boolean ProductoModificar(String dato, int id) // update product
{

try
{
    byte bytes[] = dato.getBytes();
    rs.setRecord(id, bytes, 0, dato.length());
return true;
}
catch(Exception ex)
{
return false;
}
}

public boolean ProductoEliminar(int id)// delete product
{

try
{
    rs.deleteRecord(id);
return true;
}
catch(Exception ex)
{
return false;
}
}

我不知道如何创建查找产品的方法(使用其名称的一部分,或使用其条形码)以及将返回什么?也许是一个数组?
例如,所有产品的名称(或描述)中都写有 coca 或
查找带有条形码的独特产品。
(这是一个类,我将实例化以使用它的方法)

【问题讨论】:

    标签: java-me midlet j2mepolish rms


    【解决方案1】:

    您可以尝试以下代码,根据您的使用情况进行编辑。我正在使用以下代码从 RMS 数据中搜索项目。

    public boolean SearchRecord(String Rec, int pos )
    {
        String [] data = getRecordData();
    
        Rec = Rec.substring(0,pos);
        for ( int i = 0 ; i < data.length ; i++ )
        {
            data[i] = data[i].substring(0, pos );
            if ( Rec.toString().trim().equals(data[i].toString().trim()) )
            {
                data = null; // System.gc();
                return true;
            }
        }
    
        data = null; // System.gc();
        return false;
    }
    

    通过改变“pos”变量的值,你可以实现你的目标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-29
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 2014-06-07
      • 1970-01-01
      • 2017-06-12
      • 2015-04-08
      相关资源
      最近更新 更多