简体   繁体   中英

Android, how to replace slashes in path

i have an image path : "UploadFile\\\\/UserProfile\\\\/Female.jpg" . How to replace "\\\\/" with "/" ? i have tried :

  1. replaceAll("\\\\/","/")
  2. replaceAll("\\\\\\\\/","/")

Code:

adapter_profilepic = objUser.getProfilePicture().replaceAll("\\/","/");

This works :

String src = "UploadFile\\/UserProfile\\/Female.jpg";
src = src.replaceAll("\\\\/","/");
System.out.println(src);

output:

UploadFile/UserProfile/Female.jpg

You said you tried it, but check it again.

According documentation your string is used as regular expression . Why you don't using replace :

String adapter_profilepic = objUser.getProfilePicture().replace("\\\\/","/");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM