Jake Aarons Jake Aarons - 1 year ago 114
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() {
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) {
Toast.makeText(MainActivity.this, strings.toString(), Toast.LENGTH_LONG).show();


Sample Image

enter image description here

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download