skip to Main Content

I have a String, named a[1]. How can I remove "" to make the final output as below?

/data/user/0/com.xxx/xxx/ABC Home_2-2-2_12 Jan 2024-12 Jan 2024.pdf  

Below is the code

var a = contentDisposition!.split(";");
debugPrint("eev ${a[1]}"); // filename="ABC Home_2-2-2_12 Jan 2024-12 Jan 2024.pdf"

var c = a[1].replaceAll("filename=", "");
var d = (c.trim());
var bytes = await consolidateHttpClientResponseBytes(response);
String dir = (await getApplicationDocumentsDirectory()).path;

File file = File("$dir/$d");
String path = file.path;
debugPrint(path);  // /data/user/0/com.xxx/xxx/"ABC Home_2-2-2_12 Jan 2024-12 Jan 2024.pdf"

2

Answers


  1. You can use .replaceAll('"', '');

    Login or Signup to reply.
  2. var d = c.replaceAll('"', '').trim(); // Remove double quotes and trim spaces
    

    Add the above line in your code

    var a = contentDisposition!.split(";");
    debugPrint("eev ${a[1]}"); // filename="ABC Home_2-2-2_12 Jan 2024-12 Jan 2024.pdf"
    
    var c = a[1].replaceAll("filename=", "");
    var d = c.replaceAll('"', '').trim(); // Remove double quotes and trim spaces
    var bytes = await consolidateHttpClientResponseBytes(response);
    String dir = (await getApplicationDocumentsDirectory()).path;
    
    File file = File("$dir/$d");
    String path = file.path;
    debugPrint(path); // /data/user/0/com.xxx/xxx/ABC Home_2-2-2_12 Jan 2024-12 Jan 2024.pdf
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search