英文:
Include Double Backslash as plain text symbols in a String
问题
我有一个普通的字符串,其中包含"\"。然而,Java 似乎在看到双反斜杠时尝试对字符串进行格式化。有没有办法让字符串完全忽略反斜杠的格式化?
String Test = "文件位置在:C:\\Folder\\File.txt";
输出:
Test = "文件位置在:C:\Folder\File.txt";
期望输出:
Test = "文件位置在:C:\\Folder\\File.txt";
英文:
I have a plain String where it contains "\". However Java seems to be trying to format the String when it sees the Double Backslash. Is there a way to tell the String to completely ignore Backslash formatting?
String Test = "File location is: C:\\Folder\\File.txt";
Output:
Test = "File location is: C:\Folder\File.txt"
Desired output:
Test = "File location is: C:\\Folder\\File.txt"
答案1
得分: 0
尝试这个:
public class Sample {
public static void main(String[] args){
String test = "文件位置是:C:\\\\文件夹\\\\文件.txt";
System.out.println("测试 = "+ test);
}
}
输出:
测试 = 文件位置是:C:\\文件夹\\文件.txt
英文:
Try this :
public class Sample {
public static void main(String[] args){
String test = "File location is: C:\\\\Folder\\\\File.txt";
System.out.println("Test = "+ test);
}
}
Output :
Test = File location is: C:\\Folder\\File.txt
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论