How to remove unwanted character in file path using Android

时间:2016-08-31 12:33:12

标签: android

How can I remove comma, opening and closing square bracket after the new image path appears in the Toast??

Consider the following code:

btnSave = (Button) findViewById(R.id.btnSaveAlbum);
            btnSave.setOnClickListener(new View.OnClickListener() {
                @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                @Override
                public void onClick(View v) {


                  if (requestCode == 200 && resultCode == Activity.RESULT_OK) {
                        String[] apath = data.getStringArrayExtra("all_path");
                        ArrayList<String> strings = new ArrayList<String>();

                        for (String string : apath) {
                            strings.add(string);
                            Toast.makeText(MainActivity.this, strings.toString(), Toast.LENGTH_LONG).show();
                        }

                    }
                }
            });

Sample Image

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以这样做:

String myString = "[mytext]";
myString = myString.replace("[", "");
myString = myString.replace("]", "");

String[] parts = myString.split(",");
String part1 = parts[0];
String part2 = parts[1];
...