Question about backslash and how to convert it into a forward slash?

Source: Internet
Author: User

 

A forward slash, also known as a left slash, indicates "/"; a backslash, also known as a right slash, indicating "\".

 
Package COM. autonavi. test; public class testpath {public static void main (string [] ARGs) {string Path = "d :\\ APACHE-Tomcat-6.0.26 \ webapps \ createpdf"; system. out. println (PATH); // Regular Expression in Java, which is represented by "\" string path2 = path. replaceall ("\\\\", "/"); system. out. println (path2 );}}
Output result: D: \ apache-Tomcat-6.0.26 \ webapps \ createpdf
D:/Apache-Tomcat-6.0.26/webapps/createpdf in Unix/Linux, the path is separated by a forward slash "/", for example, "/home/huaow "; in Windows, backslashes are used to separate paths, for example, C: \ WINDOWS \ SYSTEM ". Sometimes we can see the path format "C: \ Windows \ System", that is, using two backslash to separate the paths, this method is often seen in network applications or programming. In fact, the above path can be replaced by "C:/Windows/system" without errors. However, if you write "C: \ WINDOWS \ SYSTEM", there may be various strange errors. The cause of the above problem should be analyzed from the aspect of string parsing. Anyone who has learned programming should know that when outputting a string in C, If You Want To output a line feed, add the '\ n' sign. Similarly, output a tab, '\ T' is added, that is, the backslash ("\") is used to combine the characters following it and convert them to other characters. According to this principle, if you want to output double quotation marks ('"'), you need to enter '\"' to correctly write the string containing double quotation marks into the memory. What if you want to enter a backslash? It's easy. Just press. Some people may have noticed that, if the path string "C: \ WINDOWS \ SYSTEM" is handed to the C compiler for compilation, the string actually written into the memory does not contain the Backslash "\", and even the letters that follow the backslash are escaped into other characters. If you call it again, the problem may occur. String Parsing is not limited to the C compiler, Java compiler, parsing of some configuration files, Web servers, and so on, and will all encounter this problem of string parsing, traditional Windows uses the path separation form of a single slash, which may cause unnecessary errors when parsing the file path, therefore, the form that separates paths with the double Backslash "\" is displayed. No matter whether the parsing engine parses the backslash into an escape character or not, the final result obtained in the memory is "\", and no problem will occur. From this we can also see that windows or DoS is not fully considered at the initial stage of design, in order to distinguish it from some characteristics of UNIX, change the path Separation Method of the forward slash "/" in UNIX to the Backslash "\". In the early days of the doscommand line, a normal file name cannot contain spaces. If a file name contains spaces, command Parsing cannot distinguish it from parameter. For example, if you want to enter the "huaow yuan" Directory (ignore the 8.3 naming rule first) and directly enter "CD huaow yuan", the command line will resolve it to enter the "huaow" directory, the "Yuan" parameter is not expected. In UNIX, if a file name contains spaces, you can directly add a backslash "\" before the space to escape the file name, thus, it is quite different from the command parameters (usually separated by spaces ). In UNIX, just enter "CD huaow \ yuan" (Add "\" before the space in front of yuan "\"), the command line correctly identifies "huaow yuan" and enters this directory. Of course, other methods (for example, the file name is enclosed in double quotation marks) have been used in subsequent versions of Windows to solve the space problem.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.