In java, I have a file path, for example 'C: \ A \ B \ C', I want it to be changed to '' C: / A / B / C '. how to replace backslash?
String text = "C:\\A\\B\\C"; String newString = text.replace("\\", "/"); System.out.println(newString);
Since you requested a regular expression, you will have to escape the \ character several times:
String path = "c:\\A\\B\\C"; System.out.println(path.replaceAll("\\\\", "/"));
You can do this using the String.replace method:
public static void main(String[] args) { String foo = "C:\\foo\\bar"; String newfoo = foo.replace("\\", "/"); System.out.println(newfoo); }
To replace all occurrences of a given character:
String result = candidate.replace( '\\', '/' );
Regards, Cyril
String oldPath = "C:\\A\\B\\C"; String newPath = oldPath.replace('\\', '/');
Source: https://habr.com/ru/post/922088/More articles:Access Vibration Function in Windows 8 WinRT? - windowsJava console menu library. Is there an easy way to create a command line menu? - javaHow to install and use sqlobject + mysql on python hardware? - mysqliOS 5 - Is there a way to turn off autocomplete in a UITextView, but keep spell checking (red underline)? - iosreplace "\" with "" in java - javaUnrecognized selector sent to UIViewController instance - objective-cLocal minimum in unsorted array - algorithmHow to disable Magento Duplicate profiles and billing agreements? - magentoHow to limit user input of 24-format time in the input field? - javascript"Intent cannot be resolved to type error in eclipse - androidAll Articles