[Q#5756748][A#5756784] Java how to replace backslash?
https://stackoverflow.com/q/5756748
In java, I have a file path, like 'C:\A\B\C', I want it changed to ''C:/A/B/C'. how to replace the backslashes?
Answer
https://stackoverflow.com/a/5756784
APIzation
String text = "C:\\A\\B\\C";
String newString = text.replace("\\", "/");
System.out.println(newString);
package com.stackoverflow.api;
public class Human5756784 {
public static String replaceBackslash(String text) {
String newString = text.replace("\\", "/");
return newString;
}
}
package com.stackoverflow.api;
/**
* Java how to replace backslash?
*
* @author APIzator
* @see <a href="https://stackoverflow.com/a/5756784">https://stackoverflow.com/a/5756784</a>
*/
public class APIzator5756784 {
public static String java(String text) throws Exception {
String newString = text.replace("\\", "/");
return newString;
}
}