Home > Common Problem > body text

What is the difference between forward slash and backslash

爱喝马黛茶的安东尼
Release: 2019-07-20 16:39:27
Original
20530 people have browsed it

“在绝大多数地方,用的都是/(slash),包括Mac/Linux,也包括URL。你唯一需要记住的是,Microsoft这个怪鸡在自己的操作系统里面偏要用\(backslash),使得自己与众不同。

根据上面的说法,你很容易记住谁是“正”斜杠,谁是“反”斜杠,这个世界上就只有Microsoft是反的,别人都是“正”的,因为它用的那个叫做 backslash。”

What is the difference between forward slash and backslash

Unix使用斜杠/作为路径分割符,而Web应用最先是使用在Unix系统上面,所以目前所有的网络地址都采用斜杠/作为分隔符。

Windows由于使用斜杠/作为DOS命令提示符的参数标志了,为了不混淆,所以采用反斜杠\作为路径分隔符。所以目前windows系统上的文件浏览器都是用反斜杠\作为路径分隔符。随着发展,DOS系统已经被淘汰了,命令提示符也用得很少,斜杠和反斜杠在大多数情况下可以互换,没有影响。

相关推荐:《常见问题

我在cmd.exe验证了一下:

 正斜杠:

What is the difference between forward slash and backslash

反斜杠:

 What is the difference between forward slash and backslash

正斜杠:

What is the difference between forward slash and backslash

反斜杠:

 What is the difference between forward slash and backslash

的确,现在在cmd中,已经不区分正斜杠和反斜杠了!

知道这个背景后,可以总结一下结论:

(1)浏览器地址栏网址使用 正斜杠/;

(2)windows文件浏览器上使用 反斜杠\;

(3)出现在htm url()属性中的路径,指定的路径是网络路径,所以必须使用 正斜杠/;

<div style="background-image:url(/Image/Control/title.jpg); background-repeat:repeat-x; padding:10px 10px 10px 10px">
</div>// 如果url后面用反斜杠,就不会显示任何背景
Copy after login

(4)出现在普通字符串的路径,如果代表的是windows文件路径,则使用 正斜杠/和 反斜杠\是一样的;如果代表的是网络文件路径,则必须使用 正斜杠/;

<img  src=".\Image/Control/ding.jpg" / alt="What is the difference between forward slash and backslash" > // 本地文件路径,/ 和 \ 是等效的
<img  src="./Image\Control\cai.jpg" / alt="What is the difference between forward slash and backslash" >
<img  src="http://hiphotos.baidu.com/yuhua522/pic/item/01a949c67e1023549c163df2.jpg" / alt="What is the difference between forward slash and backslash" > 
// 网络文件路径,一定要使用 斜杆/
Copy after login

另外在编程中,常用反斜杠\加字符表示转义字符,如\0表示“空字符”\r表示“回车”,\n表示“换行”等。

而"\\"则表示反斜杠\的转义字符,在编程中常用于表示反斜杠\不是普通的字符,而是路径的分隔符。如用一个字符串存储保存文件的路径时,路径为F:\caffe\Temp\image.jpg;则用字符串存储时,应该写为:

str=F:\\caffe\\Temp\\image.jpg;
Copy after login

因为若不这样表示,则反斜杠\将会当作普通字符,而非路径的分隔符。

The above is the detailed content of What is the difference between forward slash and backslash. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!