Jake Aarons Jake Aarons - 3 months ago 14
Android Question

How to remove unwanted character in file path using 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

Answer

You can do something like this:

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

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