-1

我的数据库用括号返回我的值我如何删除括号表单字符串并在我的数组字符串中保存没有括号值?help me pelase help me value is proper getting i just want to remove the bracket around my string and save in ArrayList Meal_groupid

           static ArrayList<String> Meal_groupid = new ArrayList<String>();
        Meal_groupid.add(mCursor2.getString(mCursor2.getColumnIndex("meal_group_id")));


        value is = "[AT]";



       i did  like this 


           String formatedString = "[ABC]"

                    .replace("[", "")   //remove the right bracket
                    .replace("]", "");

    Log.i("Formating Stirng",""+formatedString);

   Meal_groupid.add(mCursor2.getString(mCursor2.getColumnIndex("meal_group_id")).replace("[", 
                      "").replace("]", ""));
              Log.i("MEalGroup ID",""+Meal_groupid);



    in     logcat  Formating Stirng    ABC


             MEalGroup ID     
4

2 回答 2

0

当您设置或获取字符串时,您可以进行替换以删除 [ 和 ]。

例如:

Meal_groupid.add(mCursor2.getString(mCursor2.getColumnIndex("meal_group_id")).replace("[", "").replace("]", ""));

希望这可以帮助。

于 2013-11-01T11:37:41.727 回答
0

据我所知,“[”被认为是正则表达式,所以你需要使用替换字符串

mString.replaceAll("\\[", " ");
于 2013-11-01T12:25:44.167 回答