Android,如何在路径中替换斜杠

时间:2012-11-28 12:07:33

标签: android

我有一张图片路径:"UploadFile\\/UserProfile\\/Female.jpg"。如何将"\\/"替换为"/"? 我试过了:

  1. replaceAll("\\/","/")
  2. replaceAll("\\\\/","/")
  3. 代码:

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

2 个答案:

答案 0 :(得分:1)

This works

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

输出:

UploadFile/UserProfile/Female.jpg

你说你试过了,但又检查了一下。

答案 1 :(得分:0)

根据documentation,您的字符串将用作regular expression。为什么你不使用replace

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