2017-04-08 48 views
0

我有一個字符串"http:\/\/i.ytimg.com\/vi\/0vxOhd4qlnA\/maxresdefault.jpg"Java從字符串中刪除轉義字符

我想要它像"http://i.ytimg.com/vi/0vxOhd4qlnA/maxresdefault.jpg"

我嘗試了幾乎所有可用的stackoverflow刪除反斜槓或轉義字符,但沒有任何工作。 我試過了:

1) .replace("\\","") 
2) .replaceAll("\\","") 
3) .replace("\\\\/","/") 
4) .replaceAll("\\\\/","/") 

在此先感謝! 馬拉里

+0

HTTP地址「我幾乎嘗試了一切[.. 。]「=>這些嘗試必須成爲你問題的一部分。否則,它是無關緊要的! – Seelenvirtuose

+0

將其添加到問題中 –

回答

0

如果構建HTTP字符串,你可以做如下

System.out.println(httpString.replace('\\', '/')); 

,或者如果你想從用戶使用

 String httpString = ""; 
     Scanner scanner = new Scanner(System.in); 
     System.out.print("Enter the improper URL: "); 
     httpString = scanner.nextLine(); 
     System.out.println(newString.replace('\\', '/'));